Regular expression Matching newline in multiline text with an alternate without using DOT

From Code Trash
Jump to: navigation, search

\w matches any word character, and \W matches anything that isn't a word character.

So, [\w\W] matches anything, including a newline


for example removing c style comments

/\*[\w\W]*?\*/

another example is getting all text within a div

<div class=\"validtext_erea\">([\w\W]*?)<\/div>


Usually we use it as (.*?) but this matches all characters except newline.

So the alternate char class w is used to find all chars and non chars.

The question mark is used to include laziness because the * chars is greedy.


Reference
http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_pt2.html
See this for more modifiers.
http://www.regular-expressions.info/modifiers.html
For a long time i have been looking for this
http://www.regular-expressions.info/dot.html