Friday, 15 March 2013

regex - php preg_match non greedy? -



regex - php preg_match non greedy? -

i have string (from file):

ilx (new 2013!) overview: to the lowest degree expensive route honda's premium-label goodness drivetrain: 2 four-cylinder engines take gas-electric hybrid; front-wheel-drive only.

how string:

$writeup = file_get_contents($car_files_path . $manufacture . '/stories/'.$story);

i want match overview line (overview: to the lowest degree expensive route honda's premium-label goodness). best way accomplish this.

i tried .*\n, match , new line. there way create regex non-greedy?

i have tried: preg_match('/^overview:\s.*$/im', $writeup, $overall_matches) , don't matches

add ? after quantifier create ungreedy. in case, regex .*?\n.

to match line origin "overview: ", utilize regex:

/^overview:\s.*$/im

the m modifier allows ^ , $ match start , end of lines instead of entire search string. note there no need create ungreedy since . not match newlines unless utilize s modifier - in fact, making ungreedy here bad performance.

php regex

No comments:

Post a Comment