Perl-style Regular Expressions allow you to place a single character option (FLAG) behind the regular expression mode to modify the matching interpretation or behavior. For example, to perform case-insensitive matching, you can simply use the I flag:
Preg_match ('/cat/I', 'Stop, Catherine! '); // Returns true if returns is true.
Table 4-12 shows the modifiers from Perl supported in Perl-Compatible Regular Expressions:
Table 4-12: Perl flag
| Modifier |
Yi |
| /Regexp/I |
Case-insensitive matching |
| /Regexp/s |
Match a period (.) to any character, including a line break (\ n) |
| /Regexp/x |
Remove blank spaces and comments from the Mode |
| /Regexp/m |
Make ^ match the content after the line break (\ n), the dollar sign ($) matches the content before the line break (\ n) |
| /Regexp/e |
If the replacement string is a PHP code, run eval () to obtain the actual replacement string. |
PHP's Perl-Compatible Regular Expression functions also support other modifiers not supported in Perl, as shown in Table 4-13:
Table 4-13: Other PHP flags
| Modifier |
Yi |
| /Regexp/U |
Reverse the greed of sub-models; * match as few as possible with + rather than as much as possible. |
| /Regexp/u |
Treat pattern strings as UTF-8 Encoding |
| /Regexp/X |
If a backslash is followed by a character with no special meaning, an error is generated. |
| /Regexp/ |
Position the anchor at the beginning of the string as if there is a ^ in the pattern. |
| /Regexp/D |
Make $ match the end of only one line |
| /Regexp/S |
Make the expression parser more careful to check the structure of the mode, so that the second Runtime (such as in a loop) speeds up |