RegExp /s Flag
Example
let text = "Line\nLine.";
let pattern = /Line./gs;
let result = text.match(pattern);
Try it Yourself »
Description
The /s (dotAll) flag allows the . (dot) metacharacter to match any character, including line terminators (\n, \r, \u2028, \u2029).
Without /s, \n does not match line terminators.
Syntax
new RegExp("regexp", "s")
or simply:
/regexp/s
See Also:
The Corresponding Property: dotAll
Regular Expression Methods
Regular Expression Search and Replace can be done with different methods.
These are the most common:
String Methods
| Method | Description | 
|---|---|
| match(regex) | Returns an Array of results | 
| matchAll(regex) | Returns an Iterator of results | 
| replace(regex) | Returns a new String | 
| replaceAll(regex) | Returns a new String | 
| search(regex) | Returns the index of the first match | 
| split(regex) | Returns an Array of results | 
RegExp Methods
| Method | Description | 
|---|---|
| regex.exec() | Returns an Iterator of results | 
| regex.test() | Returns true or false | 
Browser Support
/regexp/s is a JavaScript 2018 feature.
ES 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 | 
 
