id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Mmdn_RegExp/exec_120_0.txt
Specification --- [ ECMAScript Language Specification # sec-regexp.prototype.exec ](https://tc39.es/ecma262/multipage/text- processing.html#sec-regexp.prototype.exec)
Mmdn_RegExp/Mmdn_RegExp_7_3.txt
xt) * [ ` RegExp.rightContext ($') ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext) * [ ` RegExp.$1, …, RegExp.$9 ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n) ## Help improve MDN Was this page helpful to you? Yes No [ Learn how to contribute ](https://github....
Mmdn_RegExp/exec_38_0.txt
* [ JavaScript
Mmdn_RegExp/exec_51_0.txt
All browser compatibility updates at a glance
Mmdn_RegExp/Regularexpressions_218_0.txt
* [ Web Technologies ](/en-US/docs/Web) * [ Learn Web Development ](/en-US/docs/Learn) * [ MDN Plus ](/en-US/plus) * [ Hacks Blog ](https://hacks.mozilla.org/)
Mmdn_RegExp/exec_54_0.txt
Learn how to use MDN Plus
Mmdn_RegExp/Regularexpressions_93_0.txt
A regular expression pattern is composed of simple characters, such as ` /abc/ ` , or a combination of simple and special characters, such as ` /ab*c/ ` or ` /Chapter (\d+)\.\d*/ ` . The last example includes parentheses, which are used as a memory device. The match made with this part of the pattern is remembered for ...
Mmdn_RegExp/exec_119_0.txt
## Specifications
Mmdn_RegExp/exec_116_0.txt
You can also use ` exec() ` without creating a [ ` RegExp ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) object explicitly:
Mmdn_RegExp/toString_87_0.txt
### Using toString()
Mmdn_RegExp/Regularexpressions_86_0.txt
* Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:
Mmdn_RegExp/exec_144_0.txt
Visit [ Mozilla Corporation’s ](https://www.mozilla.org) not-for-profit parent, the [ Mozilla Foundation ](https://foundation.mozilla.org/) . Portions of this content are ©1998– 2024 by individual mozilla.org contributors. Content available under [ a Creative Commons license ](/en- US/docs/MDN/Writing_guideli...
Mmdn_RegExp/Regularexpressions_1_0.txt
[ MDN Web Docs ](/en-US/) Open main menu
Mmdn_RegExp/toString_94_0.txt
new RegExp("\n").toString() === "/\\n/"; // true
Mmdn_RegExp/exec_121_0.txt
## Browser compatibility
Mmdn_RegExp/Regularexpressions_43_0.txt
](/en-US/docs/Web/Accessibility)
Mmdn_RegExp/toString_4_0.txt
](/en-US/docs/Web)
Mmdn_RegExp/Regularexpressions_152_0.txt
To include a flag with the regular expression, use this syntax:
Mmdn_RegExp/Regularexpressions_115_0.txt
` _x_ * ` , ` _x_ + ` , ` _x_ ? ` , ` _x_ { _n_ } ` , ` _x_ { _n_ ,} ` , ` _x_ { _n_ , _m_ } ` |
Mmdn_RegExp/Mmdn_RegExp_10_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/Regularexpressions_9_0.txt
Code used to describe document style
Mmdn_RegExp/Regularexpressions_190_0.txt
form.addEventListener("submit", (event) => { event.preventDefault(); testInfo(input); });
Mmdn_RegExp/toString_76_0.txt
## Try it
Mmdn_RegExp/Regularexpressions_94_0.txt
**Note:** If you are already familiar with the forms of a regular expression, you may also read [ the cheat sheet ](/en- US/docs/Web/JavaScript/Guide/Regular_expressions/Cheatsheet) for a quick lookup for a specific pattern/construct.
Mmdn_RegExp/toString_50_0.txt
* [ Updates
Mmdn_RegExp/Regularexpressions_185_0.txt
#### JavaScript
Mmdn_RegExp/Mmdn_RegExp_28_5.txt
web%2Fjavascript%2Freference%2Fglobal_objects%2Fregexp%2Fexec%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen- US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FRegExp%2Fexec%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen- us%2Fweb%2Fjavascript%2Freference%2Fg...
Mmdn_RegExp/Mmdn_RegExp_18_5.txt
ss multiple lines. [ ` RegExp.prototype.source ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source) The text of the pattern. [ ` RegExp.prototype.sticky ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) Whether or not the search is sticky. [ ` RegExp.prototype.u...
Mmdn_RegExp/Mmdn_RegExp_29_2.txt
t/Reference/Global_Objects/Object/constructor) 2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 13. Methods 1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated...
Mmdn_RegExp/exec_43_0.txt
](/en-US/docs/Web/Accessibility)
Mmdn_RegExp/Mmdn_RegExp_6_3.txt
ew data. ## See also * [ ` RegExp.prototype.lastIndex ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) * [ ` RegExp.prototype.exec() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) * [ ` RegExp.prototype.dotAll ` ](/en-US/docs/Web/JavaScript/Reference/Global_Object...
Mmdn_RegExp/Mmdn_RegExp_9_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/exec_145_0.txt
Deprecated
Mmdn_RegExp/Regularexpressions_5_0.txt
* [ HTML
Mmdn_RegExp/Mmdn_RegExp_5_4.txt
/Reference/Global_Objects/RegExp/@@search) * [ ` RegExp.prototype[@@split]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@split) * [ ` RegExp.prototype.exec() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) * [ ` RegExp.prototype.test() ` ](/en-US/docs/Web/JavaScript/Refer...
Mmdn_RegExp/toString_33_0.txt
Learn to structure web content with HTML
Mmdn_RegExp/toString_48_0.txt
Get real-time assistance and support
Mmdn_RegExp/Regularexpressions_194_0.txt
An online tool to learn, build, & test Regular Expressions.
Mmdn_RegExp/Mmdn_RegExp_23_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/Regularexpressions_75_0.txt
14. [ for ](/en-US/docs/Web/JavaScript/Reference/Statements/for) 15. [ for await...of ](/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) 16. [ for...in ](/en-US/docs/Web/JavaScript/Reference/Statements/for...in) 17. [ for...of ](/en-US/docs/Web/JavaScript/Reference/Statements/for...of) 18. [ function ](/...
Mmdn_RegExp/toString_55_0.txt
](/en-US/plus/docs/features/overview)
Mmdn_RegExp/Regularexpressions_95_0.txt
### Using simple patterns
Mmdn_RegExp/exec_68_0.txt
## In this article
Mmdn_RegExp/exec_86_0.txt
The 0-based index of the match in the string.
Mmdn_RegExp/Mmdn_RegExp_13_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/javascriptregexpexer_5_0.txt
**Visual Presentation:**
Mmdn_RegExp/Mmdn_RegExp_8_3.txt
ult = /^hello/.test(str); console.log(result); // true The following example logs a message which depends on the success of the test: js function testInput(re, str) { const midstring = re.test(str) ? "contains" : "does not contain"; console.log(`${str} ${midstring} ${re.source...
Mmdn_RegExp/toString_40_0.txt
](/en-US/docs/Learn/JavaScript)
Mmdn_RegExp/exec_131_0.txt
[ MDN logo ](/)
Mmdn_RegExp/Mmdn_RegExp_25_3.txt
JavaScript enabled. Enable JavaScript to view data. ## See also * [ ` RegExp.input ($_) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input) * [ ` RegExp.lastParen ($+) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen) * [ ` RegExp.leftContext ($`) ` ](/en-US/docs/Web/...
Mmdn_RegExp/Regularexpressions_71_0.txt
1. [ Overview ](/en-US/docs/Web/JavaScript/Reference/Global_Objects) 2. [ AggregateError ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) 3. [ Array ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) 4. [ ArrayBuffer ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) 5. [ ...
Mmdn_RegExp/Mmdn_RegExp_20_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/exec_148_0.txt
]: Non-standard. Check cross-browser support before using.
Mmdn_RegExp/exec_105_0.txt
In addition, ` re.lastIndex ` will be set to ` 25 ` , due to this regex being global.
Mmdn_RegExp/toString_52_0.txt
](/en-US/plus/updates)
Mmdn_RegExp/Regularexpressions_4_0.txt
](/en-US/docs/Web)
Mmdn_RegExp/Regularexpressions_195_0.txt
[ Regex tester ](https://regex101.com/)
Mmdn_RegExp/exec_56_0.txt
* [ FAQ
Mmdn_RegExp/exec_137_0.txt
* [ Product help ](https://support.mozilla.org/products/mdn-plus) * [ Report an issue ](/en-US/docs/MDN/Community/Issues)
Mmdn_RegExp/Regularexpressions_128_0.txt
Parentheses around any part of the regular expression pattern causes that part of the matched substring to be remembered. Once remembered, the substring can be recalled for other use. See [ Groups and backreferences ](/en- US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences#using_groups) for more...
Mmdn_RegExp/exec_84_0.txt
If the match succeeds, the ` exec() ` method returns an array and updates the [ ` lastIndex ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) property of the regular expression object. The returned array has the matched text as the first item, and then one item for each capturing group of the m...
Mmdn_RegExp/toString_32_0.txt
* [ HTML
Mmdn_RegExp/Mmdn_RegExp_0_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/toString_65_0.txt
* English (US)
Mmdn_RegExp/Regularexpressions_133_0.txt
In the following example, the script uses the ` exec() ` method to find a match in a string.
Mmdn_RegExp/Regularexpressions_126_0.txt
_Why isn't this built into JavaScript?_ There is a [ proposal ](https://github.com/tc39/proposal-regex-escaping) to add such a function to RegExp.
Mmdn_RegExp/Regularexpressions_171_0.txt
#### Using unicode regular expressions
Mmdn_RegExp/exec_96_0.txt
When using ` exec() ` , the global flag has no effect when the sticky flag is set — the match is always sticky.
Mmdn_RegExp/toString_31_0.txt
](/en-US/docs/Learn)
Mmdn_RegExp/Regularexpressions_211_0.txt
## MDN
Mmdn_RegExp/exec_40_0.txt
](/en-US/docs/Learn/JavaScript)
Mmdn_RegExp/Mmdn_RegExp_12_5.txt
Community/Issues) ## Our communities * [ MDN Community ](/en-US/community) * [ MDN Forum ](https://discourse.mozilla.org/c/mdn/236) * [ MDN Chat ](/discord) ## Developers * [ Web Technologies ](/en-US/docs/Web) * [ Learn Web Development ](/en-US/docs/Learn) * [ MDN Plus ](/en-US/plus) * [ Hacks Blog...
Mmdn_RegExp/Regularexpressions_192_0.txt
## Tools
Mmdn_RegExp/exec_62_0.txt
* [ Log in ](/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FRegExp%2Fexec) * [ Sign up for free ](/users/fxa/login/authenticate/?next=%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FRegExp%2Fexec)
Mmdn_RegExp/Regularexpressions_217_0.txt
## Developers
Mmdn_RegExp/exec_102_0.txt
// Match "quick brown" followed by "jumps", ignoring characters in between // Remember "brown" and "jumps" // Ignore case const re = /quick\s(?<color>brown).+?(jumps)/dgi; const result = re.exec("The Quick Brown Fox Jumps Over The Lazy Dog");
Mmdn_RegExp/toString_1_0.txt
[ MDN Web Docs ](/en-US/) Open main menu
Mmdn_RegExp/Regularexpressions_7_0.txt
](/en-US/docs/Web/HTML)
Mmdn_RegExp/exec_72_0.txt
## In this article
Mmdn_RegExp/Mmdn_RegExp_5_2.txt
Web/JavaScript/Reference/Global_Objects/Object/constructor) 2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 13. Methods 1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter_...
Mmdn_RegExp/toString_67_0.txt
Filter sidebar Clear filter input
Mmdn_RegExp/Regularexpressions_220_0.txt
* [ Website Privacy Notice ](https://www.mozilla.org/privacy/websites/) * [ Cookies ](https://www.mozilla.org/privacy/websites/#cookies) * [ Legal ](https://www.mozilla.org/about/legal/terms/mozilla) * [ Community Participation Guidelines ](https://www.mozilla.org/about/governance/policies/participation/)
Mmdn_RegExp/Regularexpressions_163_0.txt
and get the same result.
Mmdn_RegExp/exec_73_0.txt
* Try it * Syntax * Description * Examples * Specifications * Browser compatibility * See also
Mmdn_RegExp/Mmdn_RegExp_16_1.txt
astIndex ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) 9. [ ` RegExp.lastMatch ($&) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch) Deprecated 10. [ ` RegExp.lastParen ($+) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen) Deprecated...
Mmdn_RegExp/exec_118_0.txt
This will log a message containing ` 'hello world!' ` .
Mmdn_RegExp/exec_27_0.txt
Learn web development
Mmdn_RegExp/Mmdn_RegExp_11_2.txt
/Object/constructor) 2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 13. Methods 1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated 2. [ ` Object.protot...
Mmdn_RegExp/Regularexpressions_147_0.txt
// "The value of lastIndex is 0"
Mmdn_RegExp/Mmdn_RegExp_18_0.txt
* Skip to main content * Skip to search * Skip to select language [ MDN Web Docs ](/en-US/) Open main menu * References [ References ](/en-US/docs/Web) * [ Overview / Web Technology Web technology reference for developers ](/en-US/docs/Web) * [ HTML Structure of content on the web ](/en-US/do...
Mmdn_RegExp/Regularexpressions_168_0.txt
console.log(re.exec(str)); // ["fee ", index: 0, input: "fee fi fo fum"] console.log(re.exec(str)); // ["fi ", index: 4, input: "fee fi fo fum"] console.log(re.exec(str)); // ["fo ", index: 7, input: "fee fi fo fum"] console.log(re.exec(str)); // null
Mmdn_RegExp/exec_80_0.txt
` str `
Mmdn_RegExp/toString_66_0.txt
* [ Español ](/es/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString) * [ Français ](/fr/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString) * [ 日本語 ](/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString) * [ Português (do Brasil) ](/pt-BR/docs/Web/JavaScript/Reference/Glob...
Mmdn_RegExp/Regularexpressions_183_0.txt
html
Mmdn_RegExp/Regularexpressions_24_0.txt
Web technology reference for developers
Mmdn_RegExp/javascriptregexpexer_23_0.txt
* **Weekly Trends and Language Statistics** * [ Weekly Trends and Language Statistics ](https://www.w3resource.com/weekly-trends-and-language-statistics.php)
Mmdn_RegExp/exec_101_0.txt
Consider the following example:
Mmdn_RegExp/exec_44_0.txt
* Plus [ Plus ](/en-US/plus) * [ Overview
Mmdn_RegExp/Regularexpressions_16_0.txt
](/en-US/docs/Web/HTTP)
Mmdn_RegExp/toString_75_0.txt
The **` toString() ` ** method of [ ` RegExp ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances returns a string representing this regular expression.