1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Regular Expressions

22. RegExp Methods

clr gif

As well as having lots of properties, regular expression objects also have a number of methods (functions) associated with them. We looked at two of these methods in the first two tutorials in the series. Just to remind you the test(string) method tests if the regular expression pattern matches the string that is passed in and returns true or false. The exec(string) method locates the first match within the string and returns that matching text.

The compile(pattern,'ig') method is used to replace the pattern that a given regular expression is using. This allows the same code to be reused for matching different expressions without having to define multiple regular expression objects. Th method is not used very much as most people find it easier just to define another regular expression.

The toString() and valueOf() methods perform their usual functions of converting the regular expression into text.

©2016 About.com. All rights reserved.