I wrote a regex to fetch string from HTML, but it seems the multiline flag doesn\'t work.
This is my pattern and I want to get the text in h1
tag.
[\s\S]
did not work for me in nodejs 6.11.3. Based on the RegExp documentation, it says to use [^]
which does work for me.
(The dot, the decimal point) matches any single character except line terminators: \n, \r, \u2028 or \u2029.
Inside a character set, the dot loses its special meaning and matches a literal dot.
Note that the m multiline flag doesn't change the dot behavior. So to match a pattern across multiple lines, the character set [^] can be used (if you don't mean an old version of IE, of course), it will match any character including newlines.
For example:
/This is on line 1[^]*?This is on line 3/m
where the *? is the non-greedy grab of 0 or more occurrences of [^].