The multiline property of the RegExp object in JavaScript indicates whether the 'm' flag, which enables multiline searching, is set. This property is read-only.
The syntax of RegExp.multiline property is:
RegExp.prototype.multiline
This multiline property of RegExp whether or not to search in strings across multiple lines. This property is read-only.
RegExp.multiline returns value of type Boolean
.
In JavaScript, we can check if the 'm' flag is enabled for a RegExp object by accessing the multiline
property.
For example,
regex
with the 'm' flag /^abc/m
.multiline
property of regex
to see if it is true.const regex = /^abc/m;
const isMultilineEnabled = regex.multiline;
console.log(isMultilineEnabled);
true
In JavaScript, we can compare the multiline
property of RegExp objects with and without the 'm' flag.
For example,
regexWithM
with the 'm' flag /^abc/m
.regexWithoutM
without the 'm' flag /^abc/
.multiline
property of both objects and log the results to the console.const regexWithM = /^abc/m;
const regexWithoutM = /^abc/;
console.log(regexWithM.multiline); // true
console.log(regexWithoutM.multiline); // false
true false
In JavaScript, we can use the multiline
property in conditional statements to perform different actions based on whether the 'm' flag is enabled.
For example,
regex
with the 'm' flag /^abc/m
.multiline
property of regex
in an if
statement.'Multiline searching is enabled.'
to the console; otherwise, we log 'Multiline searching is not enabled.'
.const regex = /^abc/m;
if (regex.multiline) {
console.log('Multiline searching is enabled.');
} else {
console.log('Multiline searching is not enabled.');
}
Multiline searching is enabled.
In this JavaScript tutorial, we learned about multiline property of RegExp: the syntax and few working examples with output and detailed explanation for each example.