multiline Property

Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression.

rgExp.multiline

Arguments

  • rgExp
    Required. An instance of a Regular Expression object.

Remarks

The multiline property is read-only, and 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. The default value is false.

If multiline is false, "^" matches the position at the beginning of a string, and "$" matches the position at the end of a string. If multiline 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".

Example

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 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.

function RegExpMultilineDemo(flag){
    // The flag parameter is a string that contains
    // g, i, or m. The flags can be combined.

    // Check flags for validity.
    if (flag.match(/[^gim]/))
       {
       return ("Flag specified is not valid");
       }

    // Create the string on which to perform the replacement.
    var ss = "The man hit the ball with the bat ";
    ss += "\nwhile the fielder caught the ball with the glove.";

    // Replace "while" with "and".
    var re = new RegExp("^while", flag);
    var r = ss.replace(re, "and");

    // Output the multiline flag and the resulting string.
    var s = "";
    s += "Result for multiline = " + re.multiline.toString();
    s += ": " + r;

    return(s);
}

print (RegExpMultilineDemo("m"));
print (RegExpMultilineDemo(""));

Requirements

Version 5.5

Applies To:

Regular Expression Object

See Also

Concepts

Regular Expression Syntax

Reference

global Property

ignoreCase Property

Change History

Date

History

Reason

July 2009

Modified example.

Content bug fix.

March 2009

Modified example.

Information enhancement.