Is Regular Expression in String Method
The Is Regular Expression in String method determines if a string includes a regular expression. It returns one of the following values:
If the string includes a regular expression, then it returns the following value:
True
If the string does not include a regular expression, then it returns the following value:
False
This method uses the same arguments as the Get Regular Expression from String method. For more information, see Get Regular Expression from String Method.
Format
regexp.test(str)
The Is Regular Expression in String method is equivalent to regexp.exec(str)!=null.
You can write code that uses the Is Regular Expression in String method with the global attribute set on the regular expression instance. This functionality uses the lastIndex property in the same way as the Get Regular Expression from String method. For more information, see Get Regular Expression from String Method.
Example
The following example includes the Is Regular Expression in String method:
var str = "one two three tio one";
var pat = /t.o/;
rtn = pat.test(str);
// Then rtn == true.