Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
RegexBuddy—Better than a regular expression reference!

Replacement Strings Reference: Context and Case Conversion

FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
Match Context \` Insert the part of the subject string to the left of the regex match Replacing b with \` in abc yields aac YESnononononoYESnononononoYESnonononoerror
Match Context $` 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.65
nonoerror
Match Context \' Insert the part of the subject string to the right of the regex match Replacing b with \' in abc yields acc YESnononononoYESnononononoYESnonononoerror
Match Context $' 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.65
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 YESnononononoYESnonononononononononoerror
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 YESnononononoYESnonononononononononoerror
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 errornoYESnonononononononononoerror
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 errornoYESnonononononononononoerror
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 nononoYESextendednononononononononoall
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 nononoYESextendednononononononononoall
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 nononoYESextendednononononononononoall
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 nononoYESextendednononononononononoall
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 nononoYESnononononononononononononoerror
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 nononoYESnononononononononononononoerror
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 nonononononononononononononoall
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 nonononononononononononononoall
default
nonoerror
FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath

Make a Donation

Did this website just save you a trip to the bookstore? Please make a donation to support this site, and you'll get a lifetime of advertisement-free access to this site! Credit cards, PayPal, and Bitcoin gladly accepted.

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