Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
Replacement Reference
Introduction
Table of Contents
Characters
Matched Text & Backreferences
Context & Case Conversion
Conditionals
Regular Expressions Reference
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
RegexBuddy—Better than a regular expression reference!

Replacement Strings Reference: Context and Case Conversion

FeatureSyntaxDescriptionExampleJGsoft .NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
Match Context \` (backslash backtick) Insert the part of the subject string to the left of the regex match Replacing b with \` in abc yields aac YESnononononoYESnononononoYESnonononoerror
Match Context $` (dollar backtick) Insert the part of the subject string to the left of the regex match Replacing b with $` in abc yields aac YESYESerrorYESerrornoYESnoYESYESYESnonodefaultall
default
nonoerror
Match Context $PREMATCH and ${^PREMATCH} Insert the part of the subject string to the left of the regex match Replacing b with $PREMATCH in abc yields aac nonoerrorerrorerrornononononoerrornononoall
default
1.42–1.85
nonoerror
Match Context \' (backslash quote) Insert the part of the subject string to the right of the regex match Replacing b with \' in abc yields acc YESnononononoYESnononononoYESnonononoerror
Match Context $' (dollar quote) Insert the part of the subject string to the right of the regex match Replacing b with $' in abc yields acc YESYESerrorYESerrornoYESnoYESYESYESnonodefaultall
default
nonoerror
Match Context $POSTMATCH and ${^POSTMATCH} Insert the part of the subject string to the right of the regex match Replacing b with $POSTMATCH in abc yields acc nonoerrorerrorerrornononononoerrornononoall
default
1.42–1.85
nonoerror
Match Context \_ Insert the whole subject string Replacing b with \_ in abc yields aabcc nononononononononononononononononoerror
Match Context $_ Insert the whole subject string Replacing b with $_ in abc yields aabcc YESYESerrorerrorerrornoYESnonoYESerrornonononononoerror
Case Conversion \U0 and \U1 through \U99 Insert the whole regex match or the 1st through 99th backreference with all letters in the matched text converted to uppercase. Replacing .+ with \U0 in HeLlO WoRlD yields HELLO WORLD YESnononononoYESnononono3.7–3.10 errornononononoerror
Case Conversion \L0 and \L1 through \L99 Insert the whole regex match or the 1st through 99th backreference with all letters in the matched text converted to lowercase. Replacing .+ with \L0 in HeLlO WoRlD yields hello world YESnononononoYESnononono3.7–3.10 errornononononoerror
Case Conversion \F0 and \F1 through \F99 Insert the whole regex match or the 1st through 99th backreference with the first letter in the matched text converted to uppercase and the remaining letters converted to lowercase. Replacing .+ with \F0 in HeLlO WoRlD yields Hello world YESnononoextended errornoYESnononono3.7–3.10 errornononononoerror
Case Conversion \I0 and \I1 through \I99 Insert the whole regex match or the 1st through 99th backreference with the first letter of each word in the matched text converted to uppercase and the remaining letters converted to lowercase. Replacing .+ with \I0 in HeLlO WoRlD yields Hello World YESnononoextended errornoYESnononono3.7–3.10 errornononononoerror
Case Conversion \U All literal text and all text inserted by replacement text tokens after \U up to the next \E or \L is converted to uppercase. Replacing (\w+) (\w+) with \U$1 CrUeL \E$2 in HeLlO WoRlD yields HELLO CRUEL WoRlD nononoYESextendednononononono3.7–3.10 errornonoall
default
nonoerror
Case Conversion \L All literal text and all text inserted by replacement text tokens after \L up to the next \E or \U is converted to lowercase. Replacing (\w+) (\w+) with \L$1 CrUeL \E$2 in HeLlO WoRlD yields hello cruel WoRlD nononoYESextendednononononono3.7–3.10 errornonoall
default
nonoerror
Case Conversion \u The first character after \u that is inserted into the replacement text as a literal or by a token is converted to uppercase. Replacing (\w+) (\w+) with \u$1 \ucRuEl \u$2 in hElLo wOrLd yields HElLO CRuEl WOrLd nononoYESextendednononononono3.7–3.10 errornonoall
default
nonoerror
Case Conversion \l The first character after \l that is inserted into the replacement text as a literal or by a token is converted to lowercase. Replacing (\w+) (\w+) with \l$1 \lCrUeL \l$2 in HeLlO WoRlD yields heLlO crUeL woRlD nononoYESextendednononononono3.7–3.10 errornonoall
default
nonoerror
Case Conversion \u\L The first character after \u\L that is inserted into the replacement text as a literal or by a token is converted to uppercase and the following characters up to the next \E or \U are converted to lowercase. Replacing (\w+) (\w+) with \u\L$1 \uCrUeL \E\u$2 in HeLlO wOrLd yields Hello Cruel WOrLd nononoYESnonononononono3.7–3.10 errornononononoerror
Case Conversion \l\U The first character after \l\U that is inserted into the replacement text as a literal or by a token is converted to lowercase and the following characters up to the next \E or \L are converted to uppercase. Replacing (\w+) (\w+) with \l\U$1 \lCrUeL \E\l$2 in HeLlO WoRlD yields hELLO cRUEL woRlD nononoYESnonononononono3.7–3.10 errornononononoerror
Case Conversion \L\u The first character after \L\u that is inserted into the replacement text as a literal or by a token is converted to uppercase and the following characters up to the next \E or \U are converted to lowercase. Replacing (\w+) (\w+) with \L\u$1 \uCrUeL \E\u$2 in HeLlO wOrLd yields Hello Cruel WOrLd nonononononononononono3.7–3.10 errornonoall
default
nonoerror
Case Conversion \U\l The first character after \U\l that is inserted into the replacement text as a literal or by a token is converted to lowercase and the following characters up to the next \E or \L are converted to uppercase. Replacing (\w+) (\w+) with \U\l$1 \lCrUeL \E\l$2 in HeLlO WoRlD yields hELLO cRUEL woRlD nonononononononononono3.7–3.10 errornonoall
default
nonoerror
FeatureSyntaxDescriptionExampleJGsoft .NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath