Matching newline in multiline text without using DOT but with an alternate char class

Regular Expression Add comments

The Character class \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="\&quot;validtext_erea\&quot;">([\w\W]*?)&lt;\/div&gt;</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

Leave a Reply

Entries RSS