RegExp /m Flag
Example
Do a multiline search for "is" at the beginning of each line in a string:
all there
is`
let pattern = /^is/m;
Description
The/m (multiline) flag specifies amultiline match.
The/m flag affects the behavior of^ and$.
^ specifies a match at the start of a string.
$ specifies a match at the end of a string.
With/m set,^ and$ will match the start and end of each line,in a multiline string, in addition to the start and end of the entire string.
Syntax
or simply:
/regexp/m
See Also:
The Corresponding Property:multiline
Tip
To perform a global or case-insensitive search,/g and/or a/i.
Example
A global, multiline search for "is" at the beginning of each string line:
all there
is`
let pattern = /^is/gm;
Example
A global, case-insensitive, multiline search for "is" at the beginning of each string line:
all there
is`
let pattern = /^is/gmi;
Example
A global, multiline search for "is" at the end of each string line:
all there
is`
let text = "Is\nthis\nhis\n?";
let pattern = /is$/gm;
Tip
Use themultiline property to check if the/m flag is set.
Check if the "m" modifier is set:
let result = pattern.multiline;
Regular Expression Methods
Regular ExpressionSearch andReplace 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/m is an ECMAScript3 (JavaScript 1999) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |

