Insert a Conditional into the Replacement Text

The Insert Token button on the Create panel makes it easy to insert the following replacement text tokens that reinsert (part of) the regular expression match. See the Insert Token help topic for more details on how to build up a replacement text via this menu.

Conditional

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 insert the part to the left of the alternation operator into the replacement when the capturing group has participated in the match. It will insert the part to the right of the alternation operator when the capturing group has not participated in the match.

For example, the regular expression 0|(1) matches 0 or 1. The capturing group only participates in the match when the regex matches 1. The replacement string conditional (?{1}true:false) thus inserts true when the regex matches 1 and false when it matches 0.

Insert a conditional