RegExp.prototype.exec() - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

coerced to strings

The string against which to match the regular expression. All values are coerced to strings, so omitting it or passing undefined causes exec() to search for the string "undefined", which is rarely what you want.

null-prototype object

A null-prototype object of named capturing groups, whose keys are the names, and values are the capturing groups, or undefined if no named capturing groups were defined. See capturing groups for more information.

String.prototype.match()

JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, exec() can be used to iterate over mul

[Symbol.replace]()

JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, exec() can be used to iterate over mul

RegExp.prototype.test()

String.prototype.matchAll()

String.prototype.search()

rewinding lastIndex

JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, exec() can be used to iterate over mul

Finding successive matches

Warning: There are many pitfalls that can lead to this becoming an infinite loop!

Using exec() with RegExp literals

You can also use exec() without creating a RegExp object explicitly:

Learn how to contribute

This page was last modified on Jul 20, 2025 by MDN contributors.

[Symbol.matchAll]()

[Symbol.hasInstance]()

__defineGetter__()

__defineSetter__()

__lookupGetter__()