multiline Property

Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only.


The required rgExp argument is an instance of the RegExp object


The multiline property returns true if the multiline flag is set for a regular expression, and returns false if it is not. The multiline property is true if the regular expression object was created with the m flag.

If multiline is false, "^" matches the position at the beginning of a string, and "$" matches the position at the end of a string. If multline is true, "^" matches the position at the beginning of a string as well as the position following a "\n" or "\r", and "$" matches the position at the end of a string and the position preceding "\n" or "\r".


The following example illustrates the behavior of the multiline property. If you pass "m" in to the function shown below, the word "while" is replaced with the word "and". This is because with the multiline flag is set and the word "while" occurs at the beginning of the line after a newline character. The multiline flag allows the search to be performed on multiline strings.

This function returns a string with a table that shows the condition of the allowable regular expression flags, g, i, and m. The function also returns the string with all replacements made.

function RegExpPropDemo(flag){
   if (flag.match(/[^gim]/))          //Check flag for validity.
     return("Flag specified is not valid");
   var r, re, s                       //Declare variables.
   var ss = "The man hit the ball with the bat.";
   ss += "\nwhile the fielder caught the ball with the glove.";
   re = new RegExp("^while",flag);    //Specify the pattern to search for.
   r = ss.replace(re, "and");         //Replace "the" with "a".
   s = "Regular Expression property values:\n\n"
   s += "global  ignoreCase  multiline\n"
   if (re.global)                     //Test for global flag.
     s += " True     ";
     s += "False     ";
   if (re.ignoreCase)                 //Test ignoreCase flag.
     s += " True  ";
     s += "False  ";
   if (re.multiline)                  //Test multiline flag.
     s += "     True     ";
     s += "     False   ";
   s += "\n\nThe resulting string is:\n\n" + r;
   return(s);                         //Returns replacement string


Version 5.5

See Also

global property | ignoreCase Property | Regular Expression Syntax

Applies To: RegExp Object