Single line modifier - s

Q

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

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

✍: FYIcenter.com

A

The single line modifier 's', also called "dot all" modifier, modifies the behavior of the regular expression. When 's' is specified, the wildcard character "." will match the any character including the newline character treating the entire subject string as a single line. In other words,

  • When modifier "s" is not specified, "." will match any character except the newline character. This is the default behavior.
  • When modifier "s" is specified, "." will match any character including the newline character.

With the given example subject string, we can use this regular expression: to capture the entire content of the "Hello" class with single line modifier, 's', specified:

Click the button to test this regular expression here online:

2013-02-02, 2229👍, 0💬