Name
RegExp.Test Method
Syntax
RegExp.Test(string)stringUse: Required
Data Type: String
The string to be searched.
Return Value
A Boolean indicating whether a match was found.
Description
Performs a regular expression search against
string and indicates whether a match was
found
Rules at a Glance
Prior to calling the Test method, the search string should be defined by setting the Pattern property.
The method searches
stringusing the RegExp object’s Pattern property.The method returns
Trueif the search succeeds andFalseotherwise.
Programming Tips and Gotchas
Since a search is successful if one match is found, you do not have to set the RegExp object’s Global property before calling the Test method.
You can use the method to determine whether a match exists before calling either the Execute or the Replace methods.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access