Regex Non-Capturing Group – Use (?:...) Without Extra Captures

Local only

Group regex alternatives for precedence while keeping the Match All captures array free of values you do not need.

9 chars · 1 line

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex grouping behavior

How to use a non-capturing regex group

The syntax (?:...) groups tokens for alternation or quantification without creating another numbered capture. In the preloaded matcher example, cats and dogs are found while the captures array stays empty. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Non-capturing group example
  • Capture-array inspection
  • Alternation grouping
  • Match All output
  • JavaScript RegExp semantics
  • Browser-local processing

Steps

  1. Identify parentheses that exist only to control alternation or quantifier scope.
  2. Change (...) to (?:...) when no captured value is needed from that group.
  3. Run Match All and confirm the match stays the same while the captures list contains only intentionally captured values.

Non-capturing changes extraction, not grouping precedence

The ?: marker prevents the group from creating a capture slot. It does not remove the parentheses' effect on alternation, sequence, or quantifier scope.

Non-capturing group example

Group cat|dog before s? without capturing the animal token.

Pattern and input

(?:cat|dog)s? / g
cats dogs

Match All

cats
dogs
(no numbered captures)

Common questions

Frequently asked questions

Does (?:...) match differently from (...)?

The grouped matching behavior is the same; the difference is that (?:...) does not create a numbered capture.

Why avoid unnecessary captures?

Fewer incidental captures make indexes easier to maintain and can better communicate that the group exists only for structure.

Can I quantify a non-capturing group?

Yes. You can apply ?, *, +, or bounded quantifiers to a non-capturing group just like an ordinary group.

Debugging a specific Regex issue? Browse Regex troubleshooting.