Section 24.153. RegExp: regular expressions for pattern matching


24.153. RegExp: regular expressions for pattern matching

ECMAScript v3: Object RegExp

24.153.1. Literal Syntax

 /pattern/attributes 

24.153.2. Constructor

new RegExp(pattern, attributes)

24.153.2.1. Arguments

pattern

A string that specifies the pattern of the regular expression or another regular expression.


attributes

An optional string containing any of the "g", "i", and "m" attributes that specify global, case-insensitive, and multiline matches, respectively. The "m" attribute is not available prior to ECMAScript standardization. If the pattern argument is a regular expression instead of a string, this argument must be omitted.

24.153.2.2. Returns

A new RegExp object, with the specified pattern and flags. If the pattern argument is a regular expression rather than a string, the RegExp( ) constructor creates a new RegExp object using the same pattern and flags as the specified RegExp. If RegExp( ) is called as a function without the new operator, it behaves just as it would with the new operator, except when pattern is a regular expression; in that case, it simply returns pattern instead of creating a new RegExp object.

24.153.2.3. Throws

SyntaxError

If pattern is not a legal regular expression, or if attributes contains characters other than "g", "i", and "m".


TypeError

If pattern is a RegExp object, and the attributes argument is not omitted.

24.153.3. Instance Properties


global

Whether the RegExp has the "g" attribute.


ignoreCase

Whether the RegExp has the "i" attribute.


lastIndex

The character position of the last match; used for finding multiple matches in a string.


multiline

Whether the RegExp has the "m" attribute.


source

The source text of the regular expression.

24.153.4. Methods


exec( )

Performs powerful, general-purpose pattern matching.


test( )

Tests whether a string contains a pattern.

24.153.5. Description

The RegExp object represents a regular expression, a powerful tool for performing pattern matching on strings. See Chapter 11 for complete details on regular-expression syntax and use.

24.153.6. See Also

Chapter 11




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net