preg-match-all
PHP’s preg_match() and preg_match_all() functions
preg_match stops looking after the first match. preg_match_all, on the other hand, continues to look until it finishes processing the entire string. Once match is found, it uses the remainder of the string to try and apply another match. http://php.net/manual/en/function.preg-match-all.php
“Unknown modifier ‘g’ in…” when using preg_match in PHP?
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{2,4})$/gim”, ….) use: preg_match_all(“/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/im”, ….)