/I modifier 

/i was used in regular expression to make character case-insensitive. When we remove this then it makes our string case-sensitive. The example of /I modifier was given below.

<?php

$string = ‘azam’;

if(preg_match(“/AZAM/i”, $string))

{

echo ‘The string match’;

}

else

{

echo ‘No match found’;

}

?>

/s Modifier 

/s php modifier was used in regular expression to match a character new line. In the given below example

<?php

$string = ‘see’.”\n”.’at’.”\n”.’noon’.”\n”.’taxes’.”\n”;

if(preg_match(“/see.at.noon/s”, $string))

{

echo ‘pattern match’;

}

else

{

echo’ not match’;

}

?>

If we remove noon from the string, then it will not match the pattern because noon was not in the new line.

/m Modifier

If our string contains a multiple new line, then /m modifier consider this multiple line only a single new line character. Example of /m modifier was given below.

<?php

$string = ‘andriod’.”\n”.’bubbles’.”\n”.’azam’.”\n”;

if(preg_match(“/bubbles/m”, $string))

{

echo ‘Pattern Found’;

}

else

{

echo ‘Pattern not found’;

}

?>

Another example of /m modifier

<?php

$string = ‘andriod’.”\n”.’bubbles’.”\n”.’azam’.”\n”;

if(preg_match(“/andriod azam/m”, $string))
{
echo ‘Pattern Found’;
}
else
{
echo ‘Pattern not found’;
}
?>

In this example, if we want to match andriod bubbles from our string, then it does not match the pattern, because this modifier consider the multiple line as a single line while azam going to another line,while /s modifier find this string.

Reference:

http://stackoverflow.com/questions/918806/difference-between-regular-expression-modifiers-m-and-s

Advertisements