Section 24.159. RegExp.test( ): test whether a string matches a pattern


24.159. RegExp.test( ): test whether a string matches a pattern

ECMAScript v3

24.159.1. Synopsis

regexp.test(string)

24.159.1.1. Arguments

string

The string to be tested.

24.159.1.2. Returns

true if string contains text that matches regexp; false otherwise.

24.159.1.3. Throws

TypeError

If this method is invoked on an object that is not a RegExp.

24.159.2. Description

test( ) tests string to see if it contains text that matches regexp. If so, it returns true; otherwise, it returns false. Calling the test( ) method of a RegExp r and passing it the string s is equivalent to the following expression:

 (r.exec(s) != null) 

24.159.3. Example

 var pattern = /java/i; pattern.test("JavaScript");   // Returns true pattern.test("ECMAScript");   // Returns false 

24.159.4. See Also

RegExp.exec( ), RegExp.lastIndex, String.match( ), String.replace( ), String.substring( ); 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