如何使正则表达式不用引号挨饿?

Art*_*man 7 php regex unicode

如何让它不饿 - preg_match_all('/"[\p{L}\p{Nd}?-??-??? -_\.\+]+"/ui', $outStr, $matches);

Joh*_*ica 11

你的意思是非贪婪,因为找到最短的比赛而不是最长的比赛?的*,+?量词是由默认的贪婪,并会尽可能地匹配.在它们后面添加一个问号,使它们不贪婪.

preg_match_all('/"[\p{L}\p{Nd}?-??-??? -_\.\+]+?"/ui', $outStr, $matches);
Run Code Online (Sandbox Code Playgroud)

贪婪的比赛:

"foo" and "bar"
^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

非贪婪的比赛:

"foo" and "bar"
^^^^^
Run Code Online (Sandbox Code Playgroud)