jaymc Posted December 18, 2006 Share Posted December 18, 2006 Can anyone tell me whats wrong with this, I dont think its formatted correct[code]$patterns = "/\msn.com | \hotmail.com | \hotmail.co.uk/";if (preg_match($patterns, $string)) {echo "yes";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/ Share on other sites More sharing options...
roopurt18 Posted December 18, 2006 Share Posted December 18, 2006 I think you need to use grouping:[code]<?php$patterns = "/(\\msn.com)|(\\hotmail.com(.uk)?)/";if (preg_match($patterns, $string)) {echo "yes";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/#findComment-144064 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 I don't think so either. Something like this for alternation...[code]<?php$pattern = "/(msn|hotmail)\.(com|co\.uk)/";if (preg_match($pattern, $string)){ echo "Yes";}?>[/code]Although this will include msn.co.ukRegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/#findComment-144067 Share on other sites More sharing options...
jaymc Posted December 19, 2006 Author Share Posted December 19, 2006 [quote author=roopurt18 link=topic=119182.msg487787#msg487787 date=1166486062]I think you need to use grouping:[code]<?php$patterns = "/(\\msn.com)|(\\hotmail.com(.uk)?)/";if (preg_match($patterns, $string)) {echo "yes";}?>[/code][/quote]That works but it doesnt match hotmail.co.uk...Huh?And too the other guy, you cant return msn.co.uk as valid.. Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/#findComment-144095 Share on other sites More sharing options...
jaymc Posted December 19, 2006 Author Share Posted December 19, 2006 Ive just used$patterns = "/(\\@msn.com)|(\\@hotmail.com)|(\\@hotmail.co.uk)/";Working fine Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/#findComment-144100 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 In that case, I'd have thought that the following would be better. It's certainly slightly shorter.[code=php:0]$pattern = "/@((msn|hotmail)\.com|hotmail\.co\.uk)/";[/code] RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31172-preg-match/#findComment-144359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.