O
O
Optimus2018-03-09 22:58:26
PHP
Optimus, 2018-03-09 22:58:26

What is the meaning of the s and m flags in regular expressions?

Let's take for example a regular expression for one letter n without flags /n/g https://regex101.com/r/3nEjdB/1 as a result, he sees the letters n both in the first and second lines.
What is the point then if I put s - single line nothing will change like m - multiline, because even now without m it perceives the line as multiline.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2018-03-09
Pyan @marrk2

m changes the behavior of the anchors (^ and $) and s changes the behavior of the dot (.)
Your regex doesn't use (.) , (^) and ($) so you don't see the difference when adding m and s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question