id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Mmdn_RegExp/exec_134_0.txt
## MDN
Mmdn_RegExp/Mmdn_RegExp_25_4.txt
in new websites. *[ Deprecated ]: Deprecated. Not for use in new websites. *[ Non-standard ]: Non-standard. Check cross-browser support before using.
Mmdn_RegExp/toString_13_0.txt
](/en-US/docs/Web/JavaScript)
Mmdn_RegExp/Regularexpressions_104_0.txt
[ Groups and backreferences ](/en- US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences) guide
Mmdn_RegExp/Mmdn_RegExp_0_2.txt
e/Global_Objects/Function) 28. [ Generator ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) 29. [ GeneratorFunction ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction) 30. [ globalThis ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) 31. [ Infinity ]...
Mmdn_RegExp/Mmdn_RegExp_25_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_69_0.txt
* Try it * Syntax * Description * Examples * Specifications * Browser compatibility * See also
Mmdn_RegExp/exec_1_0.txt
[ MDN Web Docs ](/en-US/) Open main menu
Mmdn_RegExp/exec_46_0.txt
](/en-US/plus)
Mmdn_RegExp/toString_124_0.txt
]: Non-standard. Check cross-browser support before using.
Mmdn_RegExp/toString_86_0.txt
## Examples
Mmdn_RegExp/toString_92_0.txt
Since ` toString() ` accesses the [ ` source ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source) property, an empty regular expression returns the string ` "/(?:)/" ` , and line terminators such as ` \n ` are escaped. This makes the returned value always a valid regex literal.
Mmdn_RegExp/Regularexpressions_169_0.txt
In contrast, [ ` String.prototype.match() ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/String/match) method returns all matches at once, but without their position.
Mmdn_RegExp/toString_54_0.txt
Learn how to use MDN Plus
Mmdn_RegExp/toString_96_0.txt
Specification --- [ ECMAScript Language Specification # sec-regexp.prototype.tostring ](https://tc39.es/ecma262/multipage/text- processing.html#sec-regexp.prototype.tostring)
Mmdn_RegExp/exec_25_0.txt
](/en-US/docs/Web)
Mmdn_RegExp/toString_98_0.txt
BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
Mmdn_RegExp/Regularexpressions_76_0.txt
6. [ Character escape: \n, \u{...} ](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape) 7. [ Disjunction: | ](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction) 8. [ Input boundary assertion: ^, $ ](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Input_boundary_assert...
Mmdn_RegExp/Regularexpressions_64_0.txt
Article Actions
Mmdn_RegExp/javascriptregexpexer_13_0.txt
![Flowchart: JavaScript- Check whether the first character of a string is uppercase or not](https://www.w3resource.com/w3r_images/javascript-regexp- exercise-1.png)
Mmdn_RegExp/toString_44_0.txt
* Plus [ Plus ](/en-US/plus) * [ Overview
Mmdn_RegExp/Mmdn_RegExp_0_9.txt
JavaScript's standard, built-in objects, including their methods and properties. The term "global objects" (or standard built-in objects) here is not to be confused with **the global object** . Here, "global objects" refer to **objects in the global scope** . The **global object** itself can be accessed using the [ ...
Mmdn_RegExp/Regularexpressions_219_0.txt
[ Mozilla logo ](https://www.mozilla.org/)
Mmdn_RegExp/Regularexpressions_142_0.txt
As shown in the second form of this example, you can use a regular expression created with an object initializer without assigning it to a variable. If you do, however, every occurrence is a new regular expression. For this reason, if you use this form without assigning it to a variable, you cannot subsequently access ...
Mmdn_RegExp/Mmdn_RegExp_12_1.txt
gExp: lastIndex ` ](/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) D...
Mmdn_RegExp/Regularexpressions_189_0.txt
output.textContent = ok ? `Thanks, your phone number is ${ok[0]}` : `${phoneInput.value} isn't a phone number with area code!`; }
Mmdn_RegExp/Mmdn_RegExp_8_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_91_0.txt
### Empty regular expressions and escaping
Mmdn_RegExp/Mmdn_RegExp_20_1.txt
stIndex ` ](/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/javascriptregexpexer_28_0.txt
[ This work is licensed under a Creative Commons Attribution 4.0 International License. ](http://creativecommons.org/licenses/by-nc/4.0/)
Mmdn_RegExp/toString_122_0.txt
]: Deprecated. Not for use in new websites. *[
Mmdn_RegExp/Regularexpressions_21_0.txt
Developing extensions for web browsers
Mmdn_RegExp/Regularexpressions_187_0.txt
const re = /^(?:\d{3}|\(\d{3}\))([-/.])\d{3}\1\d{4}$/;
Mmdn_RegExp/Regularexpressions_34_0.txt
](/en-US/docs/Learn/HTML)
Mmdn_RegExp/Mmdn_RegExp_6_4.txt
it 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_guidelines/Attrib_copyright_license) . *[ ...
Mmdn_RegExp/Regularexpressions_92_0.txt
## Writing a regular expression pattern
Mmdn_RegExp/exec_136_0.txt
## Support
Mmdn_RegExp/Regularexpressions_68_0.txt
## In this article
Mmdn_RegExp/Regularexpressions_224_0.txt
Non-standard
Mmdn_RegExp/Regularexpressions_136_0.txt
const myArray = /d(b+)d/g.exec("cdbbdbsbz"); // similar to 'cdbbdbsbz'.match(/d(b+)d/g); however, // 'cdbbdbsbz'.match(/d(b+)d/g) outputs [ "dbbd" ] // while /d(b+)d/g.exec('cdbbdbsbz') outputs [ 'dbbd', 'bb', index: 1, input: 'cdbbdbsbz' ]
Mmdn_RegExp/exec_113_0.txt
* Do _not_ place the regular expression literal (or [ ` RegExp ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) constructor) within the ` while ` condition — it will recreate the regex for every iteration and reset [ ` lastIndex ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) ...
Mmdn_RegExp/exec_9_0.txt
Code used to describe document style
Mmdn_RegExp/Mmdn_RegExp_7_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/Mmdn_RegExp_2_1.txt
/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 11. [ `...
Mmdn_RegExp/exec_45_0.txt
A customized MDN experience
Mmdn_RegExp/Regularexpressions_155_0.txt
Note that the flags are an integral part of a regular expression. They cannot be added or removed later.
Mmdn_RegExp/exec_110_0.txt
This script displays the following text:
Mmdn_RegExp/exec_98_0.txt
* If you only care whether the regex matches a string, but not what is actually being matched, use [ ` RegExp.prototype.test() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) instead. * If you are finding all occurrences of a global regex and you don't care about information like capturing groups, ...
Mmdn_RegExp/Mmdn_RegExp_23_4.txt
/privacy/websites/#cookies) * [ Legal ](https://www.mozilla.org/about/legal/terms/mozilla) * [ Community Participation Guidelines ](https://www.mozilla.org/about/governance/policies/participation/) Visit [ Mozilla Corporation’s ](https://www.mozilla.org) not-for-profit parent, the [ Mozilla Foundation ](https:...
Mmdn_RegExp/Regularexpressions_100_0.txt
[ Assertions ](/en- US/docs/Web/JavaScript/Guide/Regular_expressions/Assertions) guide
Mmdn_RegExp/Mmdn_RegExp_19_1.txt
Script/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 11. [ ` RegExp.leftContext ...
Mmdn_RegExp/Mmdn_RegExp_3_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_45_0.txt
A customized MDN experience
Mmdn_RegExp/Regularexpressions_70_0.txt
1. [ JavaScript ](/en-US/docs/Web/JavaScript) 2. [ Tutorials ](/en-US/docs/Web/JavaScript/Tutorials) 3. Complete beginners 1. [ JavaScript basics ](/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics) 2. [ JavaScript first steps ](/en-US/docs/Learn/JavaScript/First_steps) 3. [ JavaScript building blocks ](...
Mmdn_RegExp/toString_101_0.txt
## Help improve MDN
Mmdn_RegExp/Mmdn_RegExp_28_3.txt
resents the entire match, the second ` indices ` entry represents the first capturing group, etc. Each entry itself is a two-element array, where the first number represents the match's start index, and the second number, its end index. The ` indices ` array additionally has a ` groups ` property, which holds a [ ` nu...
Mmdn_RegExp/Regularexpressions_8_0.txt
* [ CSS
Mmdn_RegExp/toString_104_0.txt
[ Learn how to contribute ](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you to our contribution guidelines on GitHub.") .
Mmdn_RegExp/toString_47_0.txt
* [ AI Help (beta)
Mmdn_RegExp/Regularexpressions_69_0.txt
* Creating a regular expression * Writing a regular expression pattern * Using regular expressions in JavaScript * Examples * Tools
Mmdn_RegExp/toString_113_0.txt
* [ Product help ](https://support.mozilla.org/products/mdn-plus) * [ Report an issue ](/en-US/docs/MDN/Community/Issues)
Mmdn_RegExp/Regularexpressions_124_0.txt
function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string }
Mmdn_RegExp/toString_15_0.txt
Protocol for transmitting web resources
Mmdn_RegExp/toString_117_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/Regularexpressions_78_0.txt
67. [ TypeError: can't convert BigInt to number ](/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_BigInt_to_number) 68. [ TypeError: can't convert x to BigInt ](/en-US/docs/Web/JavaScript/Reference/Errors/Cant_convert_x_to_BigInt) 69. [ TypeError: can't define property "x": "obj" is not extensible ](/en-US/doc...
Mmdn_RegExp/Mmdn_RegExp_18_3.txt
haracters with ` \ ` when included in a string) are necessary. For example, the following are equivalent: js const re = /\w+/; // OR const re = new RegExp("\\w+"); ### Special handling for regexes **Note:** Whether something is a "regex" can be [ duck-typed ](https://en.wikipedia.org/wi...
Mmdn_RegExp/exec_75_0.txt
The **` exec() ` ** method of [ ` RegExp ` ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances executes a search with this regular expression for a match in a specified string and returns a result array, or [ ` null ` ](/en- US/docs/Web/JavaScript/Reference/Operators/null) .
Mmdn_RegExp/exec_104_0.txt
Property | Value ---|--- ` [0] ` | ` "Quick Brown Fox Jumps" ` ` [1] ` | ` "Brown" ` ` [2] ` | ` "Jumps" ` ` index ` | ` 4 ` ` indices ` | ` [[4, 25], [10, 15], [20, 25]] ` ` groups: { color: [10, 15 ]} ` ` input ` | ` "The Quick Brown Fox Jumps Over The Lazy Dog" ` ` groups ` | ` { color: "brown" } `
Mmdn_RegExp/Mmdn_RegExp_14_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_123_0.txt
Non-standard
Mmdn_RegExp/exec_26_0.txt
* Guides [ Guides ](/en-US/docs/Learn) * [ Overview / MDN Learning Area
Mmdn_RegExp/exec_60_0.txt
Search MDN Clear search input Search
Mmdn_RegExp/Regularexpressions_51_0.txt
All browser compatibility updates at a glance
Mmdn_RegExp/Regularexpressions_164_0.txt
The ` m ` flag is used to specify that a multiline input string should be treated as multiple lines. If the ` m ` flag is used, ` ^ ` and ` $ ` match at the start or end of any line within the input string instead of the start or end of the entire string.
Mmdn_RegExp/toString_64_0.txt
Article Actions
Mmdn_RegExp/Regularexpressions_28_0.txt
](/en-US/docs/Learn)
Mmdn_RegExp/toString_60_0.txt
Search MDN Clear search input Search
Mmdn_RegExp/toString_39_0.txt
Learn to run scripts in the browser
Mmdn_RegExp/exec_8_0.txt
* [ CSS
Mmdn_RegExp/Mmdn_RegExp_15_1.txt
ndex ` ](/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/toString_9_0.txt
Code used to describe document style
Mmdn_RegExp/toString_17_0.txt
* [ Web APIs
Mmdn_RegExp/Regularexpressions_191_0.txt
#### Result
Mmdn_RegExp/Regularexpressions_10_0.txt
](/en-US/docs/Web/CSS)
Mmdn_RegExp/Regularexpressions_205_0.txt
[ Learn how to contribute ](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you to our contribution guidelines on GitHub.") .
Mmdn_RegExp/Regularexpressions_201_0.txt
* [ « Previous ](/en-US/docs/Web/JavaScript/Guide/Text_formatting) * [ Next » ](/en-US/docs/Web/JavaScript/Guide/Indexed_collections)
Mmdn_RegExp/Regularexpressions_148_0.txt
The occurrences of ` /d(b+)d/g ` in the two statements are different regular expression objects and hence have different values for their ` lastIndex ` property. If you need to access the properties of a regular expression created with an object initializer, you should first assign it to a variable.
Mmdn_RegExp/toString_103_0.txt
Yes No
Mmdn_RegExp/toString_20_0.txt
* [ Web Extensions
Mmdn_RegExp/Mmdn_RegExp_13_2.txt
/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.prototype.__d...
Mmdn_RegExp/toString_2_0.txt
* References [ References ](/en-US/docs/Web) * [ Overview / Web Technology
Mmdn_RegExp/exec_31_0.txt
](/en-US/docs/Learn)
Mmdn_RegExp/Regularexpressions_80_0.txt
* Creating a regular expression * Writing a regular expression pattern * Using regular expressions in JavaScript * Examples * Tools
Mmdn_RegExp/javascriptregexpexer_7_0.txt
**Sample Solution:**
Mmdn_RegExp/Mmdn_RegExp_19_3.txt
should be done instantly, otherwise the result might be unexpected. ## Specifications Specification --- [ Legacy RegExp features # additional-properties-of-the-regexp-constructor ](https://github.com/tc39/proposal-regexp-legacy-features/#additional- properties-of-the-regexp-constructor) ## Browser compa...
Mmdn_RegExp/toString_0_0.txt
* Skip to main content * Skip to search * Skip to select language
Mmdn_RegExp/Mmdn_RegExp_0_5.txt
/en-US/docs/Web/JavaScript/Reference/Statements/for...of) 18. [ function ](/en-US/docs/Web/JavaScript/Reference/Statements/function) 19. [ function* ](/en-US/docs/Web/JavaScript/Reference/Statements/function*) 20. [ if...else ](/en-US/docs/Web/JavaScript/Reference/Statements/if...else) 21. [ import ](/e...
Mmdn_RegExp/Regularexpressions_56_0.txt
* [ FAQ
Mmdn_RegExp/exec_64_0.txt
Article Actions
Mmdn_RegExp/exec_81_0.txt
The string against which to match the regular expression. All values are [ coerced to strings ](/en- US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) , so omitting it or passing ` undefined ` causes ` exec() ` to search for the string ` "undefined" ` , which is rarely what you want.