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

JavaScript RegExp exec() Method

 JavaScript RegExp RegExp Object

exec()This method is used to search for matches in the specified string.

If a match is found, this method returns the matched text; otherwise, it returns null.

Syntax:

regex.exec(string)
var str = "www.oldtoolbag.com";
var regex = new RegExp("h");
var ans = regex.exec(str);
Test See‹/›

Browser Compatibility

All browsers fully support the exec() method:

Method
exec()YesYesYesYesYes

Parameter Value

ParameterDescription
stringString that matches the regular expression

Technical Details

Return Value:If a match is found, an array containing the matched text is returned; otherwise, null is returned.
JavaScript Version:ECMAScript 1

 JavaScript RegExp RegExp Object