Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / regular-expression

Checking for any character using regular expressions in multiline text

4.93/5 (6 votes)
30 Jan 2012CPOL 49.1K  
.* 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)