preg-match-all

“Unknown modifier 'g' in…” when using preg_match in PHP?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 11:52:31
This is the regex I'm trying to use: /^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim I found it on this site , and it works great when I try it out there. But as soon as I place it in my code, I get this message: Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\xampp\htdocs\swebook\includes\classes.php on line 22 Can anyone explain what's wrong, and why it's working on that website and not in my code? codaddict There is no modifier g for preg_match . Instead, you have to use the preg_match_all function. So instead of: preg_match("/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w

Get repeated matches with preg_match_all()

坚强是说给别人听的谎言 提交于 2019-11-26 10:02:35
问题 I\'m trying to get all substrings matched with a multiplier: $list = \'1,2,3,4\'; preg_match_all(\'|\\d+(,\\d+)*|\', $list, $matches); print_r($matches); This example returns, as expected, the last match in [1] : Array ( [0] => Array ( [0] => 1,2,3,4 ) [1] => Array ( [0] => ,4 ) ) However, I would like to get all strings matched by (,\\d+) , to get something like: Array ( [0] => ,2 [1] => ,3 [2] => ,4 ) Is there a way to do this with a single function such as preg_match_all() ? 回答1: According

“Unknown modifier 'g' in…” when using preg_match in PHP?

心不动则不痛 提交于 2019-11-26 05:54:23
问题 This is the regex I\'m trying to use: /^(\\w|\\.|-)+?@(\\w|-)+?\\.\\w{2,4}($|\\.\\w{2,4})$/gim I found it on this site, and it works great when I try it out there. But as soon as I place it in my code, I get this message: Warning: preg_match() [function.preg-match]: Unknown modifier \'g\' in C:\\xampp\\htdocs\\swebook\\includes\\classes.php on line 22 Can anyone explain what\'s wrong, and why it\'s working on that website and not in my code? 回答1: There is no modifier g for preg_match. Instead