| Feature | Syntax | Description | Example | JGsoft | Python | JavaScript | VBScript | XRegExp | .NET | Java | ICU | RE2 | Perl | PCRE2 | PHP | Delphi | R | Ruby | std::regex | Boost | Tcl | Oracle | XPath |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Conditional | ?1yes:no through ?99yes:no | Conditional referencing a numbered capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (y)?|n in yyn! with ?1yes:no yields yesyesno! | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all | no | no | no |
| Conditional | (?1yes:no) through (?99yes:no) | Conditional referencing a numbered capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (y)?|n in yyn! with (?1yes:no) yields yesyesno! | V2 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all | no | no | no |
| Conditional | (?10yes:no) through (?99yes:no) | When there are fewer capturing groups than the 2-digit number, treat this as a single-digit conditional with the "yes" part starting with a literal number instead of as an invalid conditional. | Replacing all matches of (y)?|n in yyn! with (?19yes:no) yields 9yes9yesno! | V2 | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | no | n/a | n/a | n/a |
| Conditional | ?{1}yes:no through ?{99}yes:no | Conditional referencing a numbered capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (y)?|n in yyn! with ?{1}yes:no yields yesyesno! | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all 1.42 | no | no | no |
| Conditional | (?{1}yes:no) through (?{99}yes:no) | Conditional referencing a numbered capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (y)?|n in yyn! with (?{1}yes:no) yields yesyesno! | V2 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all 1.42 | no | no | no |
| Conditional | ${1:+yes:no} through ${99:+yes:no} | Conditional referencing a numbered capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (y)?|n in yyn! with ${1:+yes:no} yields yesyesno! | V2 | no | no | no | no | no | no | no | no | no | extended | no | no | no | no | no | no | no | no | no |
| Conditional | ${1:-no} through ${99:-no} | Conditional referencing a numbered capturing group. Inserts the text captured by the group if it participated or the contents of the conditional if it didn’t. | Replacing all matches of (y)?|n in yyn! with ${1:-no} yields yyno! | V2 | no | no | no | no | no | no | no | no | no | extended | no | no | no | no | no | no | no | no | no |
| Conditional | Any numbered conditional | A conditional that references the number of a capturing group that does not exist acts as a conditional to a group that never participates. | Replacing all matches of (y)?|n in yyn! with (?9yes:no) yields nonono! | V2 error | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | extended error | n/a | n/a | n/a | n/a | n/a | all | n/a | n/a | n/a |
| Conditional | $?{name}yes:no | Conditional referencing a named capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (?'one'y)?|n in yyn! with ?{one}yes:no yields yesyesno! | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all 1.42 | no | no | no |
| Conditional | (?{name}yes:no) | Conditional referencing a named capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (?'one'y)?|n in yyn! with (?{one}yes:no) yields yesyesno! | V2 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | all 1.42 | no | no | no |
| Conditional | ${name:+yes:no} | Conditional referencing a named capturing group. Inserts the "yes" part if the group participated or the "no" part if it didn’t. | Replacing all matches of (?'one'y)?|n in yyn! with ${one:+yes:no} yields yesyesno! | V2 | no | no | no | no | no | no | no | no | no | extended | no | no | no | no | no | no | no | no | no |
| Conditional | ${name:-no} | Conditional referencing a named capturing group. Inserts the text captured by the group if it participated or the contents of the conditional if it didn’t. | Replacing all matches of (?'one'y)?|n in yyn! with ${one:-no} yields yyno! | V2 | no | no | no | no | no | no | no | no | no | extended | no | no | no | no | no | no | no | no | no |
| Conditional | Any named conditional | A conditional that references the name of a capturing group that does not exist is treated as literal text. | Replacing all matches of (y)?|n in yn! with (?{name}yes:no) yields ?{name}yes:no?{name}yes:no! | V2 error | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | n/a | extended error | n/a | n/a | n/a | n/a | n/a | all 1.42 | n/a | n/a | n/a |
| Control Verb Argument | $*MARK | Insert the argument of the last backtracking control verb to be encountered during the matching process. | Replacing a+(*:LEFT)|c+(*:RIGHT) with $*MARK in abc yields LEFTbRIGHT | no | no | no | no | error | no | error | error | no | error | 10.21 | no | no | no | no | no | no | no | no | error |
| Control Verb Argument | $REGMARK | Insert the argument of the last backtracking control verb to be encountered during the matching process. | Replacing a+(*:LEFT)|c+(*:RIGHT) with $REGMARK in abc yields LEFTbRIGHT | no | no | no | no | error | no | error | error | no | YES | error | no | no | no | no | no | no | no | no | error |
| Feature | Syntax | Description | Example | JGsoft | Python | JavaScript | VBScript | XRegExp | .NET | Java | ICU | RE2 | Perl | PCRE2 | PHP | Delphi | R | Ruby | std::regex | Boost | Tcl | Oracle | XPath |
| Quick Start | Tutorial | Search & Replace | Tools & Languages | Examples | Reference |
| Introduction | Table of Contents | Characters | Matched Text & Backreferences | Case Conversion | Context | Conditionals | Regular Expressions Reference |
Page URL: https://www.regular-expressions.info/refreplaceconditional.html
Page last updated: 17 June 2025
Site last updated: 24 October 2025
Copyright © 2003-2025 Jan Goyvaerts. All rights reserved.