1. Home
  2. Computing & Technology
  3. JavaScript

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.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.