| Replacement Text Tutorial |
| Introduction |
| Characters |
| Non-Printable Characters |
| Matched Text |
| Backreferences |
| Match Context |
| Case Conversion |
| Conditionals |
| Control Verb Argument |
Perl and PCRE2 provide away for the replacement string to insert the argument of the last backtracking control verb that participated in the match.
PCRE2 supports and as part of its replacement text syntax. Replacing a+|c+ with in abc yields LEFTbRIGHT in PCRE2. The curly braces are needed if you want to include some letters and digits immediately after the argument in the replacement string. If the regex does not have any backtracking control verbs with arguments or none of them participated in the match attempt then and are replaced with the empty string.
Perl stores the argument of the last control verb that was involved in the match in the variable $REGMARK. In a Perl script you can use this variable in the replacement because Perl interpolates variables in replacement strings. Replacing a+|c+ with in abc yields LEFTbRIGHT in a Perl script. If the regex does not have any backtracking control verbs with arguments or none of them participated in the match attempt then $REGMARK is set to TRUE which is interpolated as 1. So replacing [ab] with in abc yields 1b1.
| Quick Start | Tutorial | Search & Replace | Tools & Languages | Examples | Reference |
| Introduction | Characters | Non-Printable Characters | Matched Text | Backreferences | Match Context | Case Conversion | Conditionals | Control Verb Argument |
Page URL: https://www.regular-expressions.info/replacemark.html
Page last updated: 18 June 2025
Site last updated: 29 October 2025
Copyright © 2003-2025 Jan Goyvaerts. All rights reserved.