TESTEVERYTHING

Thursday 4 March 2021

How can I emulate DOTALL in JavaScript?

 DOTALL is a flag in most recent regex libraries that makes the . metacharacter match anything INCLUDING line breaks. JavaScript by default does not support this since the . metacharacter matches anything BUT line breaks. To emulate this behavior, simply replaces all . metacharacters by [\S\s]. This means match anything that is a single white space character OR anything that is not a white space character!

[\S\s]

No comments:

Post a Comment

Which one is right ?

Translate







Tweet