O'Reilly logo

JavaScript Pocket Reference, 2nd Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

RegExp

Literal Syntax

/pattern/attributes

Constructor

new RegExp(pattern, attributes)

Regular expression patterns are expressed using a complex grammar that is summarized earlier in this book.

Instance Properties

global

A read-only boolean that specifies whether the RegExp has the g attribute and therefore performs global matching.

ignoreCase

A read-only boolean that specifies whether the RegExp has the i attribute and therefore performs case-insensitive matching.

lastIndex

For global RegExp objects, this read/write property specifies the character position immediately following the last match; this is the first character examined for the next match.

multiline

A read-only boolean that specifies whether the RegExp has the m attribute and therefore performs multi-line matching.

source

A read-only string that holds the source text of the regular expression pattern, excluding slashes and attributes.

Methods

exec(string)

Matches string against this RegExp and returns an array containing the results of the match, or null if no match was found. Element 0 of the array is the matching text. Subsequent elements of the array contain the substrings that matched the subexpressions within the RegExp. The returned array also has an index property that specifies the start position of the match.

test(string)

Returns true if string contains text matching this RegExp, or false otherwise.

See Also

String.match( ), String.replace( ), String.search( )

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required