Checking for "any character" using regular expressions in multiline text






4.93/5 (6 votes)
".*" may not be what you want in multi-line strings
Suppose you have the string
Start this is a
multiline string End
and you want to match everything between the "Start" and "End" using a regular expression. The obvious one to use is
Start(.*)End
but in multi-line strings (strings that contain newlines) this will fail because "." does not match against newlines.
The answer? Use "[\s\S]" (match and space character or non-space character) instead of "."
Start([\s\S]*)End