Replacement Text Tutorial |
Introduction |
Characters |
Non-Printable Characters |
Matched Text |
Backreferences |
Match Context |
Case Conversion |
Conditionals |
Some applications support special tokens in replacement strings that allow you to insert the subject string or the part of the subject string before or after the regex match. This can be useful when the replacement text syntax is used to collect search matches and their context instead of making replacements in the subject string.
In the replacement text, $` (dollar backtick) is substituted with the part of the subject string to the left of the regex match in the JGsoft applications, Delphi, .NET, JavaScript, VBScript, Boost, and std::regex. It is also the variable that holds the part of the subject string to the left of the regex match in Perl. \` (backslash backtick) works in the JGsoft applications, Delphi, and Ruby.
In the same applications, you can use $' (dollar quote) or \' (backslash quote) to insert the part of the subject string to the right of the regex match.
In the replacement text, $_ is substituted with the entire subject string in the JGsoft applications, Delphi, and .NET. In Perl, $_ is the default variable that the regex is applied to if you use a regular expression without the matching operator =~. \_ is just an escaped underscore. It has no special meaning in any application.
Boost 1.42 added some alternative syntax of its own invention. $PREMATCH and ${^PREMATCH} are synonyms for $`. $POSTMATCH and ${^POSTMATCH} are synonyms for $'.
| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |
| Introduction | Characters | Non-Printable Characters | Matched Text | Backreferences | Match Context | Case Conversion | Conditionals |
Page URL: https://www.regular-expressions.info/replacecontext.html
Page last updated: 2 July 2024
Site last updated: 06 November 2024
Copyright © 2003-2024 Jan Goyvaerts. All rights reserved.