RegExp s Modifier
Example
let text = "Line\nLine.";
let pattern = /Line./gs;
let result = text.match(pattern);
Try it Yourself »
Description
This s (dotAll) flag allows the . (dot) metacharacter to match any character, including line terminator characters (like \n, \r, \u2028, \u2029).
Without s, \n does not match line terminators.
Syntax
new RegExp("regexp", "s")
or simply:
/regexp/s
Regular Expression Search Methods
In JavaScript, a regular expression text search, can be done with different methods.
With a pattern as a regular expression, these are the most common methods:
Example | Description |
---|---|
text.match(pattern) | The String method match() |
text.search(pattern) | The String method search() |
pattern.exec(text) | The RexExp method exec() |
pattern.test(text) | The RegExp method test() |
Browser Support
/regexp/s
is an ECMAScript 2018 feature.
JavaScript 2018 is supported in all modern browsers since June 2020:
Chrome 63 | Edge 79 | Firefox 78 | Safari 12 | Opera 50 |
Des 2017 | Jan 2020 | Jun 2020 | Sep 2018 | Jan 2018 |