How can I match everything in a string until the second occurrence of a delimiter with a regular expression?

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-03-25T04:29:44Z Indexed on 2011/06/24 0:22 UTC
Read the original article Hit count: 142

Filed under:
|
|

I am trying to refine a preg_match_all by finding the second occurrence of a period then a space:

<?php

$str = "East Winds 20 knots. Gusts to 25 knots. Waters a moderate chop.  Slight chance of showers.";

preg_match_all ('/(^)((.|\n)+?)(\.\s{2})/',$str, $matches);

$dataarray=$matches[2];
foreach ($dataarray as $value)
{ echo $value; }
?>

But it does not work: the {2} occurrence is incorrect.

I have to use preg_match_all because I am scraping dynamic HTML.

I want to capture this from the string:

East Winds 20 knots. Gusts to 25 knots.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex