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

JavaScript RegExp test() Methode

 JavaScript RegExp RegExp Object

test()Die Methode führt eine Suche durch, um die Übereinstimmungen eines angegebenen Strings zu finden.

If a match is found, returntrue; otherwise returnfalse.

If you just want to know if a pattern is found in the string, use test().

test() returns a boolean value, different from the string returned by exec().

Syntax:

regex.test(string)
var str = "de.oldtoolbag.com";
var regex = new RegExp("n");
var ans = regex.test(str);
Test 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