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

Regular Expression No 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


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.

See this for more modifiers
For a long time i have been looking for this

Entries RSS