Jump to content

Recommended Posts

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

 

<?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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.