vestaxpdx Posted June 13, 2012 Share Posted June 13, 2012 Hi, I have this string $my_string = "AND country='United Kingdom' OR country='France' OR country='Spain'"; I simply want to return the counties, so grab everything inside country=' ... ' I just cant figure out the reg expression. Sorry if this is mega easy. I would really appreciate some help. My code so far is: $my_string = "AND country='United Kingdom' OR country='France' OR country='Spain'"; $pattern = ""; preg_match($pattern, $my_string, $matches); print_r($matches); Link to comment https://forums.phpfreaks.com/topic/264109-need-help-with-a-simple-regular-expression-and-preg_match/ Share on other sites More sharing options...
ManiacDan Posted June 13, 2012 Share Posted June 13, 2012 $my_string = "AND country='United Kingdom' OR country='France' OR country='Spain'"; preg_match_all("/country\s*=\s*'([^']+)'/", $my_string, $foo); $countries = $foo[1]; print_r($countries); -Dan Link to comment https://forums.phpfreaks.com/topic/264109-need-help-with-a-simple-regular-expression-and-preg_match/#findComment-1353490 Share on other sites More sharing options...
vestaxpdx Posted June 13, 2012 Author Share Posted June 13, 2012 Wow thanks a million! Why are they so confusing haha Thanks again! Link to comment https://forums.phpfreaks.com/topic/264109-need-help-with-a-simple-regular-expression-and-preg_match/#findComment-1353531 Share on other sites More sharing options...
ManiacDan Posted June 13, 2012 Share Posted June 13, 2012 Regular expressions are an entirely different language. It's as confusing as learning python. Link to comment https://forums.phpfreaks.com/topic/264109-need-help-with-a-simple-regular-expression-and-preg_match/#findComment-1353577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.