Published at
Updated at
Reading time
1min
This post is part of my Today I learned series in which I share all my web development learnings.

I spoke at EnterJS a few days ago and Brian Terlson gave an excellent keynote on ES2017 and the future of JavaScript. The talk included also upcoming regular expression features that may be added to the spec in ES2017. One of these new features is the s or dotAll flag for regular expressions. So why do we need this?

It turns out that the . meta character in regular expressions is not matching all characters. You're surprised? I was, too. Let me show you some examples.

/a.b/.test('a\nb');     // false
/a.b/.test('a\rb');     // false
/a.b/.test('a\u2028b'); // false
/a.b/.test('a\u2029b'); // false

The problem with this unexpected behavior is that it can result in hard to spot bugs. The "dotall" spec proposal introduces a new /s flag which intents to fix this behavior.

/a.b/s.test('a\nb');     // true
/a.b/s.test('a\rb');     // true
/a.b/s.test('a\u2028b'); // true
/a.b/s.test('a\u2029b'); // true

What's the browser support of the dotAll flag? ๐Ÿ‘‡

MDN Compat Data (source)
Browser support info for dotAll flag
chromechrome_androidedgefirefoxfirefox_androidsafarisafari_iossamsunginternet_androidwebview_android
626279787811.111.18.062

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly โ€” Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles