- Published at
- Updated at
- Reading time
dotAll flag for regular expressions. So why do we need this?
It turns out that the
. meta character in regular expressions is not actually 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 is, that this is not what developers expect. Until Wednesday I was also expecting that
. matches any character and this leads to surprises and can result in hard to spot bugs.
The spec proposal introduces a new
/s flag which fixes this behavior. In case you want to learn more read the proposal. It explains the motivation and "fix" really well.
Edited. Mathias Bynens later shared that when the proposal is approved
/./su matches any code point including line terminator symbols.
- The navigation timing API includes the type of the current navigation
- Define where an element should be scrolled to using elem.scrollIntoView
- Is the module/nomodule bridge worth it?
- requestSubmit offers a way to validate a form before submitting it
- Optional chaining helps to avoid "undefined is not a function" exceptions