Insert a Capturing Group

The Insert Token button on the Create panel makes it easy to group regular expression tokens together and to capture their part of the match. Simply select the part of the regular expression you want to group, and then select the kind of group you want in the Insert Token menu. After adding numbered or named capturing groups, you can use Insert Token|Backreference to insert backreferences to those groups, which attempt to match the same text as most recently captured by the group they reference.

Numbered Capturing Group

A numbered capturing group groups the selected tokens together and stores their part of the match in a numbered backreference. Numbered capturing groups are automatically numbered from left to right, starting with number one. If you insert a quantifier after the capturing group, only the text matched by the last iteration will be captured. E.g. when (ab)+c matches ababc, the group captures ab. If you want to capture the text matched by all iterations, include the quantifier in the group, e.g.: ((ab)+)c.

Most regex flavors support up to 99 capturing groups. Some support only 9.

Insert a capturing group

Named Capturing group

A named capturing group works just like a numbered capturing group, except that it creates a named backreference rather than a numbered one. RegexBuddy prompts you for the name of the group that you want to insert.

Mixing named and numbered groups in a single regular expression is not recommended. Some regular expression flavors number both named and numbered groups from left to right, while others don’t include the named groups in the numbering. This leads to confusion about which numbered group is referenced by which numbered backreference.

Most applications require all named groups to have unique names. Some allow duplicate names, though sometimes only as an option. When groups with duplicate names are allowed, you should only use the same name for groups that are in separate alternatives, so that at most one group with a given name will actually capture something. Applications behave quite differently when two groups with the same name participate in a match.

Insert a named capturing group