Running Regular Expressions

When we want to actually match our pattern against a string, we use the exec() method. This method takes the pattern and compares it to the string. The result is placed in another object (which is also be an array).

foundMatch = re.exec(ordString)

We can also take a shortcut and simply code this:

foundMatch = re(ordString)

but it doesn't work in all browsers.

Information about the match is stored in the foundMatch object. Information about the match is also stored in the re object and in the RegExp object. When you use regular expressions, information is spread all over the place. Here's some code in Example 17-2 to spell out what all the various property values are.

Example 17-2. Seeing all property values
 <html> ...

Get Advanced JavaScript™: Insights and Innovative Techniques now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.