In the previous section, we wrote
var re = /[bcr]at/
The content "[bcr]at" is the regular expression. There is a regular expression object (or regexp object) that has the regular expression as a component (property). The regexp object has other properties and methods. We shall see these in the series.
Creating a RegExp Object
You create a RegExp object using a literal text format e.g. /[bcr]at/ , or the RegExp constructor function.
The literal text format is used as follows:
The constructor function is used as follows:
new RegExp("pattern"[, "flags"])
Note that the two forward slashes do not enclose the pattern in the constructor function. The pattern is enclosed by quotation marks. The flags are optional (more on that shortly).