Check out a free preview of the full JavaScript: The Recent Parts course

The "dotall Mode" Lesson is part of the full, JavaScript: The Recent Parts course featured in this preview video. Here's what you'd learn in this lesson:

Kyle demonstrates how to utilize the dotall mode to select elements of a string.

Preview
Close

Transcript from the "dotall Mode" Lesson

[00:00:00]
>> Kyle Simpson: Third feature that is gonna be a big deal in certain use cases, that was added in ES 2018, is what is called the .all mode. Specifically, it's a new flag that you can add onto the end of your regular expression. So in addition to having g for global, and m for multiline, and i for case insensitive, and those sorts of flags, there's a new flag called s.

[00:00:24]
And s turns on what is called the dot all mode. The reason why this is important is because historically, for all of regular expressions and JavaScript up to this point, the dot operator, the period, like we see on line 6, it is able to match any character, except it doesn't match across new lines.

[00:00:50]
So you're only able to match on that exact line, which is why the code on line 6 doesn't find any match. Because it can't find brown and over, since the dot in that dot-star can't span across a newline. If we then turn on the dot all mode, the dot is able to match all characters, including new lines.

[00:01:13]
So now, we're able to make regular expression matches across lines.
>> Kyle Simpson: Just three of a variety of changes that have either landed, or are landing soon. Another couple of features, or another regular expression feature that landed, not something that a lot of you will use, but a new flag that was added, which is slash u, and it turns on Unicode-aware mode for your regular expressions.

[00:01:44]
Because JavaScript regular expressions typically only work with the ASCII character set, and they don't really treat the extended Unicode code space as individual characters. But now you can turn on Unicode awareness for your regular expressions, if you need it. It also gives you some additional syntax for Unicode escape sequences in your regular expressions.

[00:02:05]
But a bunch of really cool stuff that has landed, and is landing in regular expressions, is finally gonna bring this feature up to more parity with regular expression support in other languages. And that should hopefully bring some needed relief to all the frustration that we have. We naturally don't love writing regular expressions, at least most of us.

[00:02:26]
But it should bring some very necessary relief to those problems. Any questions about these additions, or improvements to regular expressions?

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now