how to make it not hungry - preg_match_all('/"[\p{L}\p{Nd}а-яА-ЯёЁ -_\.\+]+"/ui', $outStr, $matches);
Do you mean non-greedy, as in find the shortest match instead of the longest? The *
, +
, and ?
quantifiers are greedy by default and will match as much as possible. Add a question mark after them to make them non-greedy.
preg_match_all('/"[\p{L}\p{Nd}а-яА-ЯёЁ -_\.\+]+?"/ui', $outStr, $matches);
Greedy match:
"foo" and "bar"
^^^^^^^^^^^^^^^
Non-greedy match:
"foo" and "bar"
^^^^^
See: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
U (PCRE_UNGREEDY)
This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by ?. It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern or by a question mark behind a quantifier (e.g. .*?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With