Developer Resources
RegExp
Overview
A class that represents a regular expression.
Base Class
Constructor
- RegExp(pattern : String)
- RegExp(pattern : String, flags : String)
Arguments
- pattern
- A string that contains a regular expression.
- flags
- A String that contains of the avalable flags "g", "i" and "m". "g" means that the search is global, "i" that the search is case-insensitive and "m" switches to multiline mode.
Methods
- RegExp.exec
- Searches a string for a pattern.
- RegExp.test
- Searches a string for a pattern.
- RegExp.toString
- Returns a string that represents the regular expression
Inherited Methods
- Object.hasOwnProperty
- Checks for the existence of an object property
- Object.toLocaleString
- Returns a string that represents the object.
- Object.toString
- Returns a string that represents the object.
- Object.valueOf
- Returns the 'primitive' value of the object.
Example
// sample string containing some numbers var string = "First Number: 1234; Second Number: 5678"; // regular expression to match whole numbers var regex = new RegExp("[0-9]+","mg"); // find each regular expression match in the string var result; while ((result = regex.exec(string)) != null) { // if we have a match, do something alert(result[0]); }
RegExp.exec
- function RegExp.exec(text : String) : Array(String)
Arguments
- text
- The text to search with the regular expression.
Returns
Returns an Array containing the results of searching text for the regular expression. Returns null if no text match was found.
Description
Searches the text for the string that the regular expression represents and returns the results in an Array. Returns null if no text match was found.
RegExp.test
- function RegExp.test(text : String) : Array(String)
Arguments
- text
- The text to search with the regular expression.
Returns
Returns true if the pattern matches, false otherwise.
Description
Calling the test() method determines if the regular expression matches the string specified in the text parameter. If so, the call returns true. It is identical to "RegExp.exec(text) != null"
RegExp.toString
- function RegExp.toString() : String
Returns
Returns a string containing the regular expression.
Description
Returns a string that represents the regular expression.