22. RegExp Methods
Join the Discussion
More of this Feature
Introduction Pattern Matching Ignore Case and Global Replacing Matches Spliting Matches Start and End Meta Characters Character Classes Repetitions Greedy, Reluctant, etc. Predefined Classes Special Characters ASCII and Unicode Boundaries Grouping Back References Non-Capturing Groups Lookahead Multiline Mode The RegExp Object Properties of RegExp More Properties of RegExp
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.