RegExp m Modifier
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript RegExp m Modifier

❮ JavaScript RegExp Object

Example

Do a multiline search for "is" at the beginning of each line in a string:

var str = "\nIs th\nis it?";
var patt1 = /^is/m;
Try it Yourself »

Definition and Usage

The m modifier is used to perform a multiline match.

The m modifier treat beginning (^) and end ($) characters to match the beginning or end of each line of a string (delimited by \n or \r), rather than just the beginning or end of the string.

Note: The m modifier is case-sensitive and will stop the search after the first match. To perform a global, case-insensitive, multiline search, use this modifier together with "g" and "i".

Tip: Use the multiline property to specify whether or not the m modifier is set.


Browser Support

Expression
m Yes Yes Yes Yes Yes

Syntax

new RegExp("regexp", "m")

or simply:

/regexp/m


Technical Details

JavaScript Version: ECMAScript 3

More Examples

Example

Do a global, multiline search for "is" at the beginning of each line in a string:

var str = "\nIs th\nis h\nis?";
var patt1 = /^is/gm;
Try it Yourself »

Example

Do a global, case-insensitive, multiline search for "is" at the beginning of each line in a string:

var str = "\nIs th\nis h\nis?";
var patt1 = /^is/gmi;
Try it Yourself »

Example

Do a global, multiline search for "is" at the end of each line in a string:

var str = "Is\nthis\nhis\n?";
var patt1 = /is$/gm;
Try it Yourself »

❮ JavaScript RegExp Object