Multiple line modifier - m

Q

What is the multiple line modifier? How to use it?

How the multiple line modifier can be used on this example text:

✍: FYIcenter.com

A

The multiple line modifier 'm' modifies the behavior of the regular expression. When 'm' is specified, the subject string will be treated as as multiple lines instead of a single line. In other words,

  • When modifier "m" is not specified, "^" and "$" will only match the start of the subject string and the end of the subject string. This is the default behavior.
  • When modifier "m" is specified, "^" and "$" will match the start and the end of any line within the subject string.

For example, '^(.*)$' will produce multiple matches, one match per line, if the subject string has multiple line breaks and multiple line modifier 'm' is specified.

With the given example subject string, we can use this regular expression: to capture the date in each line with multiple line modifier, 'm', specified:

Click the button to test this regular expression here online:

2013-02-02, 2252👍, 0💬