The dotAll property of the RegExp object in JavaScript indicates whether the 's' flag, which allows the dot (.) to match newline characters, is set. This property is read-only.
The syntax of RegExp.dotAll property is:
RegExp.prototype.dotAll
This dotAll property of RegExp whether . matches newlines or not. This property is read-only.
RegExp.dotAll returns value of type Boolean
.
In JavaScript, we can check if the 's' flag is enabled for a RegExp object by accessing the dotAll
property.
For example,
regex
with the 's' flag /abc/s
.dotAll
property of regex
to see if it is true.const regex = /abc/s;
const isDotAllEnabled = regex.dotAll;
console.log(isDotAllEnabled);
true
In JavaScript, we can compare the dotAll
property of RegExp objects with and without the 's' flag.
For example,
regexWithS
with the 's' flag /abc/s
.regexWithoutS
without the 's' flag /abc/
.dotAll
property of both objects and log the results to the console.const regexWithS = /abc/s;
const regexWithoutS = /abc/;
console.log(regexWithS.dotAll); // true
console.log(regexWithoutS.dotAll); // false
true false
In JavaScript, we can use the dotAll
property in conditional statements to perform different actions based on whether the 's' flag is enabled.
For example,
regex
with the 's' flag /abc/s
.dotAll
property of regex
in an if
statement.'Dot matches newlines.'
to the console; otherwise, we log 'Dot does not match newlines.'
.const regex = /abc/s;
if (regex.dotAll) {
console.log('Dot matches newlines.');
} else {
console.log('Dot does not match newlines.');
}
Dot matches newlines.
In this JavaScript tutorial, we learned about dotAll property of RegExp: the syntax and few working examples with output and detailed explanation for each example.