X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript RegExp m Modifier

RegExp Object Reference 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

Internet Explorer Firefox Opera Google Chrome Safari

The m modifier is supported in all major browsers.


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 »


RegExp Object Reference JavaScript RegExp Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook