Aaron de Windt
Aaron de Windt

Reputation: 17718

How to match any character in regex

How can I match all characters including new line with a regex. I am trying to match all characters between brackets "()". I don't want to activate Dot matches all.

I tried

\([.\n\r]*\)

But it doesn't work.

(.*\) This doesn't work if there is an new line between the brackets.

I have been using http://regexpal.com/ to test my regular expressions. Tell me if you know something better.

Upvotes: 1

Views: 490

Answers (2)

Paul
Paul

Reputation: 141927

The first example doesn't work because inside a character class the dot is treated literally (Matches the . character instead of all characters).

\((.|[\n\r])*\)

Upvotes: 2

LukeH
LukeH

Reputation: 269648

I'd usually use something like \([\S\s]*\) in this situation.

The [\S\s] will match any whitespace or non-whitespace character.

Upvotes: 5

Related Questions