objects. RegExp objects may be created with the
RegExp() constructor, of
course, but they are more often created using a special literal syntax.
Just as string literals are specified as characters within quotation
marks, regular expression literals are specified as characters within a
pair of slash (
/) characters. Thus,
var pattern = /s$/;
This line creates a new RegExp object and assigns it to the variable
pattern. This particular RegExp object
matches any string that ends with the letter “s.” This regular expression
could have equivalently been defined with the
RegExp() constructor like this:
var pattern = new RegExp("s$");
Regular-expression pattern specifications consist of a series of characters. Most characters, including all alphanumeric characters, simply describe characters to be matched literally. Thus, the regular expression ...