替换字符串参考:符合文本与反向引用替换字符串参考:符合文本与反向引用替换字符串参考:符合文本与反向引用替换字符串参考:符合文本与反向引用
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2024年3月5日
类别
  • 正则表达式
标签
替换字符串参考:符合文本与反向引用
  • 简
  • 繁
  • En
关于正则表达式 » 正则表达式参考 » 替换字符串参考 » 替换字符串参考:符合文本与反向引用

替换参考
简介
目录
字符
符合文本与反向引用
文本与大小写转换
条件式
正则表达式参考
本网站更多内容
简介
正则表达式快速入门
正则表达式教程
替换字符串教程
应用程序与语言
正则表达式范例
正则表达式参考
替换字符串参考

替换字符串参考:符合文本与反向引用

功能语法说明范例.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
与号 \& 插入一个字面与号。 以 \& 替换会产生 & 否是是延伸否否是否否否否否sed是是否错误
完整符合 \& 插入整个正则表达式符合项。 以 [\&] 替换 \d+ 在 1a2b 中会产生 [1]a[2]b 否否否否否是否否否否否是否否否否错误
完整符合 $& 插入整个正则表达式符合项。 以 [$&] 替换 \d+ 在 1a2b 中会产生 [1]a[2]b 是错误是错误否是否是是是否否缺省全部
缺省
否否错误
完整符合 & 插入整个正则表达式符合项。 以 [&] 替换 \d+ 在 1a2b 中会产生 [1]a[2]b 否否否否否否否否否否否否sedsed是否否
完整符合 \0 插入整个正则表达式符合项。 以 [\0] 替换 \d+ 在 1a2b 中会产生 [1]a[2]b 否否否否是是否否否否否是sedsed是否错误
完整符合 $0 插入整个正则表达式符合项。 以 [$0] 替换 \d+ 在 1a2b 中会产生 [1]a[2]b 是是错误是是是否否否是否否缺省
VC’08–VC’13
全部
缺省
否否是
完整符合 \g<0> 插入整个正则表达式符合项。 将 \d+ 取代为 [\g<0>] 在 1a2b 会产生 [1]a[2]b 否否否否否否否否否否是否否否否否错误
完整符合 $MATCH 和 ${^MATCH} 插入整个正则表达式符合项。 将 \d+ 取代为 [$MATCH] 在 1a2b 会产生 [1]a[2]b 否错误错误错误否否否否否错误否否否全部
缺省
1.42–1.83
否否错误
反向引用 \1 到 \9 插入与前 9 个捕获组之一相符的文本。 将 (a)(b)(c) 取代为 \3\3\1 在 abc 会产生 cca 否否是否是是是否否否是是sed是是是错误
反向引用 \10 到 \99 插入与捕获组 10 到 99 相符的文本。 否否否否是是否否否否是否否否否否否
反向引用和字面值 \10 到 \99 如果捕获组少于 2 位数,则将其视为单位数反向引用后接字面数字,而不是无效的反向引用。 将 (a)(b)(c) 取代为 \39\38\17 在 abc 会产生 c9c8a7 不适用不适用不适用不适用否是不适用不适用不适用不适用否不适用不适用不适用不适用不适用不适用
反向引用 $1 到 $9 插入与前 9 个捕获组之一相符的文本。 将 (a)(b)(c) 取代为 $3$3$1 在 abc 会产生 cca 是是是是是是否是是是否否缺省全部
缺省
否否是
反向引用 $10 到 $99 插入与捕获组 10 到 99 相符的文本。 是是是是是是否是是是否否缺省全部
缺省
否否是
反向引用和字面值 $10 到 $99 如果捕获组少于 2 位数,则将其视为单位数反向引用后接字面数字,而不是无效的反向引用。 将 (a)(b)(c) 取代为 $39$38$17 在 abc 会产生 c9c8a7 ECMA是否否否是不适用是是否不适用不适用否否不适用不适用是
反向引用 ${1} 到 ${99} 插入与第 1 到第 99 个捕获组相符的文本。 将 (a)(b)(c) 替换为 ${3}${3}${1},在 abc 中会产生 cca 是错误是是是是否否否是否否否全部
缺省
否否错误
反向引用 \g<1> 到 \g<99> 插入与第 1 到第 99 个捕获组相符的文本。 将 (a)(b)(c) 替换为 \g<3>\g<3>\g<1>,在 abc 中会产生 cca 否否否否否否否否否否是否否否否否错误
命名反向引用 ${name} 插入与命名捕获组「name」相符的文本。 将 (?'one'a)(?'two'b) 替换为 ${two}${one},在 ab 中会产生 ba 是7错误是否是否否否是否否否否否否错误
命名反向引用 $+{name} 插入与命名捕获组「name」相符的文本。 将 (?'one'a)(?'two'b) 替换为 $+{two}$+{one},在 ab 中会产生 ba 否错误5.10错误否否否否否错误否否否全部
缺省
1.42–1.83
否否错误
命名反向引用 $name 插入与命名捕获组「name」相符的文本。 将 (?'one'a)(?'two'b) 替换为 $two$one,在 ab 中会产生 ba 否错误错误是否否否否否错误否否否否否否错误
命名反向引用 \g<name> 插入与命名捕获组「name」相符的文本。 将 (?P<one>a)(?P<two>b) 替换为 \g<two>\g<one>,在 ab 中会产生 ba 否否否否否是否否否否是否否否否否错误
无效的反向引用 任何支持的反向引用语法 表示大于最高编号群组的数字或不存在的群组名称的反向引用会以空字符串取代。 否错误是错误是是是否否错误错误是缺省 VC’08–VC’22
sed VC’15–VC’22
是是是是
无效的反向引用 任何支持的反向引用语法 表示大于最高编号群组的数字或不存在的群组名称的反向引用会视为插入在替换中的文本。 是错误否错误否否否是是错误错误否sed
VC’08–VC’13 错误
否否否否
非参与群组的反向引用 任何支持的反向引用语法 非参与捕获组的反向引用会以空字符串取代。 是是是错误是是是是是是3.5是是是是是是
最后的反向引用 \+ 插入实际参与比对中最高编号捕获组比对到的文本。 在 ab 中以 [\+] 取代 (a)(z)? 会产生 [a]b 否否否否否是否否否否否是否否否否错误
最后的反向引用 \+ 插入最高编号捕获组比对到的文本,不论它是否参与比对。 在 ab 中以 [\+] 取代 (a)(z)? 会产生 []b 否否否否否否否否否否否否否否否否错误
最后的反向引用 $+ 插入实际参与比对中最高编号捕获组比对到的文本。 在 ab 中以 [$+] 取代 (a)(z)? 会产生 [a]b 否错误5.18错误否是否否否错误否否否否否否错误
最后的反向引用 $+ 插入最高编号捕获组比对到的文本,不论它是否参与比对。 在 ab 中以 [$+] 取代 (a)(z)? 会产生 []b 是错误5.8–5.16错误否否否否是错误否否否全部
缺省
1.42–1.83
否否错误
最后的反向引用 $^N 插入实际参与比对中最高编号捕获组比对到的文本。 在 ab 中以 [$^N] 取代 (a)(z)? 会产生 [a]b 否错误是错误否否否否否错误否否否全部
缺省
1.42–1.83
否否错误
最后的反向引用 $LAST_SUBMATCH_RESULT 和 ${^LAST_SUBMATCH_RESULT} 插入实际参与比对中最高编号捕获组比对到的文本。 在 ab 中以 [$LAST_SUBMATCH_RESULT] 取代 (a)(z)? 会产生 [a]b 否错误错误错误否否否否否错误否否否全部
缺省
1.42–1.83
否否错误
最后的反向引用 $LAST_PAREN_MATCH 和 ${^LAST_PAREN_MATCH} 插入最高编号捕获组比对到的文本,不论它是否参与比对。 以 [$LAST_PAREN_MATCH] 取代 (a)(z)? 在 ab 中会产生 []b 否错误错误错误否否否否否错误否否否全部
缺省
1.42–1.83
否否错误
功能语法说明范例.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
替換字串參考:符合文字與反向參照
  • 简
  • 繁
  • En
關於正規表示式 » 正規表示式參考 » 替換字串參考目錄 » 替換字串參考:符合文字與反向參照

替換參考
簡介
目錄
字元
符合文字與反向參照
文字與大小寫轉換
條件式
正規表示式參考
本網站更多內容
簡介
正規表示式快速入門
正規表示式教學
替換字串教學
應用程式與語言
正規表示式範例
正規表示式參考
替換字串參考

替換字串參考:符合文字與反向參照

功能語法說明範例.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
與號 \& 插入一個字面與號。 以 \& 替換會產生 & 否是是延伸否否是否否否否否sed是是否錯誤
完整符合 \& 插入整個正規表示式符合項。 以 [\&] 替換 \d+ 在 1a2b 中會產生 [1]a[2]b 否否否否否是否否否否否是否否否否錯誤
完整符合 $& 插入整個正規表示式符合項。 以 [$&] 替換 \d+ 在 1a2b 中會產生 [1]a[2]b 是錯誤是錯誤否是否是是是否否預設全部
預設
否否錯誤
完整符合 & 插入整個正規表示式符合項。 以 [&] 替換 \d+ 在 1a2b 中會產生 [1]a[2]b 否否否否否否否否否否否否sedsed是否否
完整符合 \0 插入整個正規表示式符合項。 以 [\0] 替換 \d+ 在 1a2b 中會產生 [1]a[2]b 否否否否是是否否否否否是sedsed是否錯誤
完整符合 $0 插入整個正規表示式符合項。 以 [$0] 替換 \d+ 在 1a2b 中會產生 [1]a[2]b 是是錯誤是是是否否否是否否預設
VC’08–VC’13
全部
預設
否否是
完整符合 \g<0> 插入整個正規表示式符合項。 將 \d+ 取代為 [\g<0>] 在 1a2b 會產生 [1]a[2]b 否否否否否否否否否否是否否否否否錯誤
完整符合 $MATCH 和 ${^MATCH} 插入整個正規表示式符合項。 將 \d+ 取代為 [$MATCH] 在 1a2b 會產生 [1]a[2]b 否錯誤錯誤錯誤否否否否否錯誤否否否全部
預設
1.42–1.83
否否錯誤
反向參照 \1 到 \9 插入與前 9 個擷取群組之一相符的文字。 將 (a)(b)(c) 取代為 \3\3\1 在 abc 會產生 cca 否否是否是是是否否否是是sed是是是錯誤
反向參照 \10 到 \99 插入與擷取群組 10 到 99 相符的文字。 否否否否是是否否否否是否否否否否否
反向參照和字面值 \10 到 \99 如果擷取群組少於 2 位數,則將其視為單位數反向參照後接字面數字,而不是無效的反向參照。 將 (a)(b)(c) 取代為 \39\38\17 在 abc 會產生 c9c8a7 不適用不適用不適用不適用否是不適用不適用不適用不適用否不適用不適用不適用不適用不適用不適用
反向參照 $1 到 $9 插入與前 9 個擷取群組之一相符的文字。 將 (a)(b)(c) 取代為 $3$3$1 在 abc 會產生 cca 是是是是是是否是是是否否預設全部
預設
否否是
反向參照 $10 到 $99 插入與擷取群組 10 到 99 相符的文字。 是是是是是是否是是是否否預設全部
預設
否否是
反向參照和字面值 $10 到 $99 如果擷取群組少於 2 位數,則將其視為單位數反向參照後接字面數字,而不是無效的反向參照。 將 (a)(b)(c) 取代為 $39$38$17 在 abc 會產生 c9c8a7 ECMA是否否否是不適用是是否不適用不適用否否不適用不適用是
反向參照 ${1} 到 ${99} 插入與第 1 到第 99 個擷取群組相符的文字。 將 (a)(b)(c) 替換為 ${3}${3}${1},在 abc 中會產生 cca 是錯誤是是是是否否否是否否否全部
預設
否否錯誤
反向參照 \g<1> 到 \g<99> 插入與第 1 到第 99 個擷取群組相符的文字。 將 (a)(b)(c) 替換為 \g<3>\g<3>\g<1>,在 abc 中會產生 cca 否否否否否否否否否否是否否否否否錯誤
命名反向參照 ${name} 插入與命名擷取群組「name」相符的文字。 將 (?'one'a)(?'two'b) 替換為 ${two}${one},在 ab 中會產生 ba 是7錯誤是否是否否否是否否否否否否錯誤
命名反向參照 $+{name} 插入與命名擷取群組「name」相符的文字。 將 (?'one'a)(?'two'b) 替換為 $+{two}$+{one},在 ab 中會產生 ba 否錯誤5.10錯誤否否否否否錯誤否否否全部
預設
1.42–1.83
否否錯誤
命名反向參照 $name 插入與命名擷取群組「name」相符的文字。 將 (?'one'a)(?'two'b) 替換為 $two$one,在 ab 中會產生 ba 否錯誤錯誤是否否否否否錯誤否否否否否否錯誤
命名反向參照 \g<name> 插入與命名擷取群組「name」相符的文字。 將 (?P<one>a)(?P<two>b) 替換為 \g<two>\g<one>,在 ab 中會產生 ba 否否否否否是否否否否是否否否否否錯誤
無效的反向參照 任何支援的反向參照語法 表示大於最高編號群組的數字或不存在的群組名稱的反向參照會以空字串取代。 否錯誤是錯誤是是是否否錯誤錯誤是預設 VC’08–VC’22
sed VC’15–VC’22
是是是是
無效的反向參照 任何支援的反向參照語法 表示大於最高編號群組的數字或不存在的群組名稱的反向參照會視為插入在替換中的文字。 是錯誤否錯誤否否否是是錯誤錯誤否sed
VC’08–VC’13 錯誤
否否否否
非參與群組的反向參照 任何支援的反向參照語法 非參與擷取群組的反向參照會以空字串取代。 是是是錯誤是是是是是是3.5是是是是是是
最後的反向參照 \+ 插入實際參與比對中最高編號擷取群組比對到的文字。 在 ab 中以 [\+] 取代 (a)(z)? 會產生 [a]b 否否否否否是否否否否否是否否否否錯誤
最後的反向參照 \+ 插入最高編號擷取群組比對到的文字,不論它是否參與比對。 在 ab 中以 [\+] 取代 (a)(z)? 會產生 []b 否否否否否否否否否否否否否否否否錯誤
最後的反向參照 $+ 插入實際參與比對中最高編號擷取群組比對到的文字。 在 ab 中以 [$+] 取代 (a)(z)? 會產生 [a]b 否錯誤5.18錯誤否是否否否錯誤否否否否否否錯誤
最後的反向參照 $+ 插入最高編號擷取群組比對到的文字,不論它是否參與比對。 在 ab 中以 [$+] 取代 (a)(z)? 會產生 []b 是錯誤5.8–5.16錯誤否否否否是錯誤否否否全部
預設
1.42–1.83
否否錯誤
最後的反向參照 $^N 插入實際參與比對中最高編號擷取群組比對到的文字。 在 ab 中以 [$^N] 取代 (a)(z)? 會產生 [a]b 否錯誤是錯誤否否否否否錯誤否否否全部
預設
1.42–1.83
否否錯誤
最後的反向參照 $LAST_SUBMATCH_RESULT 和 ${^LAST_SUBMATCH_RESULT} 插入實際參與比對中最高編號擷取群組比對到的文字。 在 ab 中以 [$LAST_SUBMATCH_RESULT] 取代 (a)(z)? 會產生 [a]b 否錯誤錯誤錯誤否否否否否錯誤否否否全部
預設
1.42–1.83
否否錯誤
最後的反向參照 $LAST_PAREN_MATCH 和 ${^LAST_PAREN_MATCH} 插入最高編號擷取群組比對到的文字,不論它是否參與比對。 以 [$LAST_PAREN_MATCH] 取代 (a)(z)? 在 ab 中會產生 []b 否錯誤錯誤錯誤否否否否否錯誤否否否全部
預設
1.42–1.83
否否錯誤
功能語法說明範例.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
Replacement Strings Reference: Matched Text and Backreferences
  • 简
  • 繁
  • En
About Regular Expressions » Regular Expressions Reference » Replacement Strings Reference » Replacement Strings Reference: Matched Text and Backreferences

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

Replacement Strings Reference: Matched Text and Backreferences

FeatureSyntaxDescriptionExample.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
Ampersand \& Insert a literal ampersand. Replacing with \& yields & noYESYESextendednonoYESnononononosedYESYESnoerror
Whole match \& Insert the whole regex match. Replacing \d+ with [\&] in 1a2b yields [1]a[2]b nononononoYESnononononoYESnonononoerror
Whole match $& Insert the whole regex match. Replacing \d+ with [$&] in 1a2b yields [1]a[2]b YESerrorYESerrornoYESnoYESYESYESnonodefaultall
default
nonoerror
Whole match & Insert the whole regex match. Replacing \d+ with [&] in 1a2b yields [1]a[2]b nonononononononononononosedsedYESnono
Whole match \0 Insert the whole regex match. Replacing \d+ with [\0] in 1a2b yields [1]a[2]b nonononoYESYESnononononoYESsedsedYESnoerror
Whole match $0 Insert the whole regex match. Replacing \d+ with [$0] in 1a2b yields [1]a[2]b YESYESerrorYESYESYESnononoYESnonodefault
VC’08–VC’13
all
default
nonoYES
Whole match \g<0> Insert the whole regex match. Replacing \d+ with [\g<0>] in 1a2b yields [1]a[2]b nonononononononononoYESnononononoerror
Whole match $MATCH and ${^MATCH} Insert the whole regex match. Replacing \d+ with [$MATCH] in 1a2b yields [1]a[2]b noerrorerrorerrornononononoerrornononoall
default
1.42–1.83
nonoerror
Backreference \1 through \9 Insert the text matched by one of the first 9 capturing groups. Replacing (a)(b)(c) with \3\3\1 in abc yields cca nonoYESnoYESYESYESnononoYESYESsedYESYESYESerror
Backreference \10 through \99 Insert the text matched by capturing groups 10 through 99. nonononoYESYESnonononoYESnononononono
Backreference and literal \10 through \99 When there are fewer capturing groups than the 2-digit number, treat this as a single-digit backreference followed by a literal number instead of as an invalid backreference. Replacing (a)(b)(c) with \39\38\17 in abc yields c9c8a7 n/an/an/an/anoYESn/an/an/an/anon/an/an/an/an/an/a
Backreference $1 through $9 Insert the text matched by one of the first 9 capturing groups. Replacing (a)(b)(c) with $3$3$1 in abc yields cca YESYESYESYESYESYESnoYESYESYESnonodefaultall
default
nonoYES
Backreference $10 through $99 Insert the text matched by capturing groups 10 through 99. YESYESYESYESYESYESnoYESYESYESnonodefaultall
default
nonoYES
Backreference and literal $10 through $99 When there are fewer capturing groups than the 2-digit number, treat this as a single-digit backreference followed by a literal number instead of as an invalid backreference. Replacing (a)(b)(c) with $39$38$17 in abc yields c9c8a7 ECMAYESnononoYESn/aYESYESnon/an/anonon/an/aYES
Backreference ${1} through ${99} Insert the text matched by capturing groups 1 through 99. Replacing (a)(b)(c) with ${3}${3}${1} in abc yields cca YESerrorYESYESYESYESnononoYESnononoall
default
nonoerror
Backreference \g<1> through \g<99> Insert the text matched by capturing groups 1 through 99. Replacing (a)(b)(c) with \g<3>\g<3>\g<1> in abc yields cca nonononononononononoYESnononononoerror
Named backreference ${name} Insert the text matched by the named capturing group “name”. Replacing (?'one'a)(?'two'b) with ${two}${one} in ab yields ba YES7errorYESnoYESnononoYESnonononononoerror
Named backreference $+{name} Insert the text matched by the named capturing group “name”. Replacing (?'one'a)(?'two'b) with $+{two}$+{one} in ab yields ba noerror5.10errornononononoerrornononoall
default
1.42–1.83
nonoerror
Named backreference $name Insert the text matched by the named capturing group “name”. Replacing (?'one'a)(?'two'b) with $two$one in ab yields ba noerrorerrorYESnononononoerrornonononononoerror
Named backreference \g<name> Insert the text matched by the named capturing group “name”. Replacing (?P<one>a)(?P<two>b) with \g<two>\g<one> in ab yields ba nononononoYESnonononoYESnononononoerror
Invalid backreference Any supported backreference syntax A backreference that indicates a number greater than the highest-numbered group or a name of a group that does not exist is replaced with the empty string. noerrorYESerrorYESYESYESnonoerrorerrorYESdefault VC’08–VC’22
sed VC’15–VC’22
YESYESYESYES
Invalid backreference Any supported backreference syntax A backreference that indicates a number greater than the highest-numbered group or a name of a group that does not exist is treated as literal text that is inserted as such in the replacement. YESerrornoerrornononoYESYESerrorerrornosed
VC’08–VC’13 error
nononono
Backreference to non-participating group Any supported backreference syntax A backreference to a non-participating capturing group is replaced with the empty string. YESYESYESerrorYESYESYESYESYESYES3.5YESYESYESYESYESYES
Last backreference \+ Insert the text matched by the highest-numbered capturing group that actually participated in the match. Replacing (a)(z)? with [\+] in ab yields [a]b nononononoYESnononononoYESnonononoerror
Last backreference \+ Insert the text matched by the highest-numbered capturing group, regardless of whether it participated in the match. Replacing (a)(z)? with [\+] in ab yields []b nonononononononononononononononoerror
Last backreference $+ Insert the text matched by the highest-numbered capturing group that actually participated in the match. Replacing (a)(z)? with [$+] in ab yields [a]b noerror5.18errornoYESnononoerrornonononononoerror
Last backreference $+ Insert the text matched by the highest-numbered capturing group, regardless of whether it participated in the match. Replacing (a)(z)? with [$+] in ab yields []b YESerror5.8–5.16errornonononoYESerrornononoall
default
1.42–1.83
nonoerror
Last backreference $^N Insert the text matched by the highest-numbered capturing group that actually participated in the match. Replacing (a)(z)? with [$^N] in ab yields [a]b noerrorYESerrornononononoerrornononoall
default
1.42–1.83
nonoerror
Last backreference $LAST_SUBMATCH_RESULT and ${^LAST_SUBMATCH_RESULT} Insert the text matched by the highest-numbered capturing group that actually participated in the match. Replacing (a)(z)? with [$LAST_SUBMATCH_RESULT] in ab yields [a]b noerrorerrorerrornononononoerrornononoall
default
1.42–1.83
nonoerror
Last backreference $LAST_PAREN_MATCH and ${^LAST_PAREN_MATCH} Insert the text matched by the highest-numbered capturing group, regardless of whether it participated in the match. Replacing (a)(z)? with [$LAST_PAREN_MATCH] in ab yields []b noerrorerrorerrornononononoerrornononoall
default
1.42–1.83
nonoerror
FeatureSyntaxDescriptionExample.NET Java Perl PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE Oracle XPath
©2015-2025 艾丽卡 support@alaica.com