RegExp /m Flag
Example
Do a multiline search for "is" at the beginning of each line in a string:
let text = `Is this
all there
is`
let pattern = /^is/m;
Try it Yourself »
Description
The /m (multiline) flag specifies a multiline 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
new RegExp("regexp", "m")
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:
let text = `Is this
all there
is`
let pattern = /^is/gm;
Try it Yourself »
Example
A global, case-insensitive, multiline search for "is" at the beginning of each string line:
let text = `Is this
all there
is`
let pattern = /^is/gmi;
Try it Yourself »
Example
A global, multiline search for "is" at the end of each string line:
let text = `Is this
all there
is`
let text = "Is\nthis\nhis\n?";
let pattern = /is$/gm;
Try it Yourself »
Tip
Use the multiline property to check if the /m flag is set.
Check if the "m" modifier is set:
let pattern = /W3S/gi;
let result = pattern.multiline;
Try it Yourself »
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/m
is an ECMAScript3 (JavaScript 1999) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |