Why this match is wrong, the regular expression puzzle
$txt = "[face= ' blackbody ']12345[/face][face= ' blackbody '] haha [/face]";
$return =preg_match_all ("/\[face=" (. *) '] (. +?) \[\/face]/", $txt, $tar);
echo "
";
Print_r ($tar);
?>
My match means the shortest string with [/face] ending with [face= ' any number '] ...
What's wrong???
Any number here seems to be ruled out [/face]
Array
(
[0] = = Array
(
[0] = [face= ' blackbody ']12345[/face][face= ' blackbody '] haha [/face]
)
[1] = = Array
(
[0] = black blackbody ']12345[/face][face= ' blackbody
)
[2] = = Array
(
[0] = = haha
)
)
The result is wrong, matching the longest string, halo
------Solution--------------------
.../\[face= ' (. *) '] ... .. = ... /\[face= ' (. *?) '] ......
No, it's greed, and it turns out like you're sticking it.
------Solution--------------------
/\[face= ' (. *) '] (. +?) \[\/face]/u plus a U can also.