Why is this matching incorrect? what is the difficulty of regular expression ;? Php $ txt = & quot; [face = 'simhei '] 12345 [/face] [face = 'simhei'] haha [/face] & quot ;; $ return = preg_match_all (& quot;/\ [face = '(. *) '] (why is the matching incorrect? it is a difficult regular expression.
$ Txt = "[face = 'simhei '] 12345 [/face] [face = 'simhei'] haha [/face]";
$ Return = preg_match_all ("/\ [face = '(. *)'] (. + ?) \ [\/Face]/", $ txt, $ tar );
Echo"
";
Print_r ($ tar );
?>
My match means the shortest string ending with [/face] with [face = 'arbitrary number...
Where is the error ???
Any number seems to be excluded [/face]
Array
(
[0] => Array
(
[0] => [face = 'simhei '] 12345 [/face] [face = 'simhei'] haha [/face]
)
[1] => Array
(
[0] => simhei '] 12345 [/face] [face = 'simhei
)
[2] => Array
(
[0] => haha
)
)
The result is incorrect. the longest matched string is dizzy.
------ Solution --------------------
...... /\ [Face = '(. *)']… => ...... /\ [Face = '(.*?) ']……
No ?, Is greedy, and the result is as you paste
------ Solution --------------------
/\ [Face = '(. *)'] (. + ?) \ [\/Face]/U can be added with a U.