English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript RegExp test() method

 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().

Syntax:

regex.test(string)
var str = "www.oldtoolbag.com";
var regex = new RegExp("n");
var ans = regex.test(str);
Test and see‹/›

Browser Compatibility

All browsers fully support the test() method:

Method
test()YesYesYesYesYes

Parameter Value

ParameterDescription
stringThe string that matches the regular expression

Technical Details

Return value:if the regular expression matches the specified string, then returntrue;otherwise returnfalse
JavaScript Version:ECMAScript 1

 JavaScript RegExp RegExp Object