Grouping In Regex Link to heading

Grouping allows us to simplify (and group) complex patterns.

In regex, any subpattern enclosed within parenthesis () is considered a group.

They are useful as we can usually

Capturing Groups and Backreferences Link to heading

The groups in the regex pattern can be captured.

The matched text inside the group is remembered and can be referenced later using backreferences.

This allows you to reuse captured portions withing the same regex pattern, or to replace a string.