Modifiers in regular expression patterns

We all like regex patterns, because it’s a great way to select, filter or replace strings, numbers or complete code blocks. How about PCRE modifiers, do you use them very often? A few weeks ago I need to use one because I get in trouble with line breaks in some string, I needed to select in some transaction. I will show in this article some examples with the “most important” PCRE modifiers.

Note each modifier is responsible for the whole pattern!

Upper and lowercase letters

Using and “i” will match both upper and lowercase letters. Use '/[a-z]*/i' to match those strings.

Match patterns across multiple lines

Normally a regex test ends at end of each line, using the “m” modifier the string is processed until the end is reached, example:

Read the rest of this entry »

Latest Articles

Popular Tags