{"slug":"ref-mdn-700738d22271d5bab461","title":"Capturing group: (...) — Description","summary":"A capturing group acts like the grouping operator in JavaScript expressions, allowing you to use a subpattern as a single atom.","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nA capturing group acts like the grouping operator in JavaScript expressions, allowing you to use a subpattern as a single atom.\n\nCapturing groups are numbered by the order of their opening parentheses. The first capturing group is numbered 1, the second 2, and so on. Named capturing groups are also capturing groups and are numbered together with other (unnamed) capturing groups. The information of the capturing group's match can be accessed through\n\nThe return value (which is an array) of {{jsxref(\"RegExp.prototype.exec()\")}}, {{jsxref(\"String.prototype.match()\")}}, and {{jsxref(\"String.prototype.matchAll()\")}} The pN parameters of the {{jsxref(\"String.prototype.replace()\")}} and {{jsxref(\"String.prototype.replaceAll()\")}} methods' replacement callback function Backreferences within the same pattern\n\n> [!NOTE] > Even in exec()'s result array, capturing groups are accessed by numbers 1, 2, etc., because the 0 element is the entire match. \\0 is not a backreference, but a character escape for the NUL character.\n\nCapturing groups in the regex source code correspond to their results one-to-one. If a capturing group is not matched (for example, it belongs to an unmatched alternative in a disjunction), the corresponding result is undefined.\n\nCapturing groups can be quantified. In this case, the match information corresponding to this group is the last match of the group.\n\nCapturing groups can be used in lookahead and lookbehind assertions. Because lookbehind assertions match their atoms backwards, the final match corresponding to this group is the one that appears to the _left_ end of the string. However, the indices of the match groups still correspond to their relative locations in the regex source.\n\nCapturing groups can be nested, in which case the outer group is numbered first, then the inner group, because they are ordered by their opening parentheses. If a nested group is repeated by a quantifier, then each time the group matches, the subgroups' results are all overwritten, sometimes with undefined.\n\nIn the example above, the outer group is matched three times\n\nMatches \"aac\", with subgroups \"aa\", undefined, and \"c\". Matches \"bbbc\", with subgroups undefined, \"bbb\", and \"c\". Matches \"ac\", with subgroups \"a\", undefined, and \"c\".\n\nThe \"bbb\" result from the second match is not preserved, because the third match overwrites it with undefined. …\n\nAttribution: Adapted from MDN Web Docs under CC-BY-SA-2.5. Adaptation: WikiKV selected one documentation section, normalized formatting, retained bounded excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","mdn","web","javascript","reference","regular-expressions","capturing-group","capturing","group","description"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/mdn/content/blob/d14bee540b5305ddeb93969618ba05102b648bb6/files/en-us/web/javascript/reference/regular_expressions/capturing_group/index.md","source_name":"MDN Web Docs","source_license":"CC-BY-SA-2.5","source_revision":"d14bee540b5305ddeb93969618ba05102b648bb6","source_path":"files/en-us/web/javascript/reference/regular_expressions/capturing_group/index.md :: Description","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.506455+00:00","url":"https://wikikv.com/k/ref-mdn-700738d22271d5bab461","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-mdn-700738d22271d5bab461","markdown":"https://wikikv.com/k/ref-mdn-700738d22271d5bab461?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-mdn-700738d22271d5bab461","json_ld":"https://wikikv.com/k/ref-mdn-700738d22271d5bab461?format=jsonld"}}