Insert a Conditional into the Regular Expression

If you’ve added one or more numbered or named capturing groups to your regular expression then you can insert conditionals that reference those groups via Insert Token|Conditional. In the window that appears, click inside the capturing group which you want the conditional to be based on. RegexBuddy automatically inserts a named conditional when you select a named group and a numbered conditional when you select a numbered group. The inserted conditional will have two blank alternatives. You’ll need to provide those to complete the conditional. The conditional will match the part to the left of the alternation operator when the capturing group has participated in the match. It will match the part to the right of the alternation operator when the capturing group has not participated in the match.

For example, the regular expression (if)?(?(1)then|else) starts with an optional group that either matches and captures if or that does not participate in the match. The second part of the regex is a conditional that references this optional group. If the group matched if then the conditional tries to match then. If it did not participate in the match then the conditional tries to match else. So the only two possible matches of this regular expression are ifthen and else.

Insert a conditional