正则表达式中反斜杠后的数字是什么意思? [英] What's the meaning of a number after a backslash in a regular expression?
本文介绍了正则表达式中反斜杠后的数字是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(a|b)\1
\1
在这个表达式中是什么意思?
What does \1
mean in this expression?
推荐答案
\1
- 表示匹配表达式中的第一个捕获组.\n
将是第 n 个捕获组.(请注意 \0
将是完整匹配).在许多引擎中,n 的上限是 9,但有些引擎也支持高达 99.
\1
- it means the first capturing group in the matched expression. \n
would be the nth capturing group. (Note that \0
would be whole match). In many engines, the upperlimit for n is 9, but some support up to 99 as well.
当在正则表达式中使用时,如(a|b)\1
,表示在a或b之后,下一个字符应该是第一个捕获的组,即a或b,所以这里的正则表达式将匹配 aa
或 bb
.
When used in regex like (a|b)\1
, it means that after a or b, the next character should be the first captured group, which is a or b so the regex here would match aa
or bb
.
这篇关于正则表达式中反斜杠后的数字是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文