HTML and CSS Reference
In-Depth Information
Figure 17.2 The result of searching for the email regular expression considered to
be the best.
17.2 Creating a Regular Expression
A regular expression is a pattern of characters. It shouldn't be any surprise by now. Java-
Script regular expressions are objects. When you create a regular expression, you test
the regular expression against a string. For example, the regular expression /green/ might
be matched against the string “The green grass grows” . If green is contained in the string,
then there is a successful match.
Building a regular expression is like building a JavaScript string. If you recall, you can
create a String object the literal way or you can use the String() constructor method. To
build a regular expression object, you can assign a literal regular expression to a variable,
or you can use the RegExp constructor to create and return a regular expression object.
17.2.1 The Literal Way
To create a regular expression object with the literal notation, you assign the regular
expression to a variable. The regular expression is a pattern of characters enclosed in
 
 
 
Search WWH ::




Custom Search