English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript RegExp RegExp Object
test()The method executes search to match the specified string.
If a match is found, returntrue; otherwise returnfalse.
Use test() if you just want to know if a pattern is found in the string.
test() returns a boolean value, different from the string returned by exec().
regex.test(string)
var str = "www.oldtoolbag.com"; var regex = new RegExp("n"); var ans = regex.test(str);Test and see‹/›
All browsers fully support the test() method:
Method | |||||
test() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
string | The string that matches the regular expression |
Return value: | if the regular expression matches the specified string, then returntrue;otherwise returnfalse |
---|---|
JavaScript Version: | ECMAScript 1 |