rohant Posted May 29, 2007 Share Posted May 29, 2007 Hi All, i want to match some specific character set 10 odd characters in a user input string. i want to find all occurences of the any of such characters. i am using preg_match_all for this.the string pattern that i am giving is a regular expression having those characters i.e "ch1|ch2|ch3" ....but i am getting only first occurence of the the char which is there in the regular expression. where i am goin wrong and how can capture all occurences of those chars. e.g pattern- "x|y|z" string to search - "this is the X string for test Z and Y are at end and are not detected" in above case the character that is matched is only X at 13th position and z and y are not matched i want to detect presence of all 3 chars. i.e x,y as well as z. how can i achieve this. i am a new bee to php so my approach might be incorrect. Please suggest the correct approach i should follow. Thanking in adavance, Regards, Rohant Quote Link to comment https://forums.phpfreaks.com/topic/53349-matching-some-specific-characters-in-a-string/ Share on other sites More sharing options...
dustinnoe Posted May 29, 2007 Share Posted May 29, 2007 <?php $pattern = "/(?im)x|y|z/"; // Using (?im) sets caseless multi line matching $string = "this is the x string for test Z and Y are at end and are not detected"; preg_match_all($pattern, $string, $matches); print_r($matches); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53349-matching-some-specific-characters-in-a-string/#findComment-263670 Share on other sites More sharing options...
rohant Posted May 29, 2007 Author Share Posted May 29, 2007 Hello Dustin, that worked. thanks! Regards, -Rohant Quote Link to comment https://forums.phpfreaks.com/topic/53349-matching-some-specific-characters-in-a-string/#findComment-263751 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.