Latest web development tutorials
 

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;

The marked text below shows where the expression gets a match:


Is th
is it?
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: 1.5

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;

The marked text below shows where the expression gets a match:

Is th
is h
is?
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;

The marked text below shows where the expression gets a match:


Is th
is h
is?
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;

The marked text below shows where the expression gets a match:

Is
this
his
?
Try it Yourself »

< JavaScript RegExp Object