如何对第 9 个反向引用后的正则表达式进行分组? [英] How do I group regular expressions past the 9th backreference?
问题描述
好的,所以我试图将记事本++中的第 9 个反向引用分组.维基说我可以使用组命名来超过第 9 个参考.但是,我似乎无法正确使用语法来进行匹配.为了简单起见,我只从两组开始.
Ok so I am trying to group past the 9th backreference in notepad++. The wiki says that I can use group naming to go past the 9th reference. However, I can't seem to get the syntax right to do the match. I am starting off with just two groups to make it simple.
示例数据
1000,1000
正则表达式.
(?'a'[0-9]*),([0-9]*)
根据 文档,我需要执行以下操作.
According to the docs I need to do the following.
(?<some name>...), (?'some name'...),(?(some name)...)
Names this group some name.
然而,结果却是找不到我的文字.有什么建议吗?
However, the result is that it can't find my text. Any suggestions?
推荐答案
你可以像那些 < 一样简单地引用组 > 910
You can simply reference groups > 9 in the same way as those < 10
即 10 美元是第十组.
i.e $10 is the tenth group.
对于(天真的)例子:
字符串:
For (naive) example:
String:
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
正则表达式查找:
Regex find:
(?:a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)
(?:a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)
替换:
10 美元
结果:
kqrstuvwxyz
kqrstuvwxyz
我的测试是在 Notepad++ v6.1.2 中进行的,并给出了我预期的结果.
My test was performed in Notepad++ v6.1.2 and gave the result I expected.
更新:这仍然适用于 v7.5.6
Update: This still works as of v7.5.6
SarcasticSully 复活了这个来问这个问题:
SarcasticSully resurrected this to ask the question:
如果要替换为第 1 组后跟字符 '0' 怎么办?"
"What if you want to replace with the 1st group followed by the character '0'?"
为此将替换更改为:
$1\x30
用组 1 和十六进制字符 30
替换 - 这是 ascii 中的 0
.
Which is replacing with group 1 and the hex character 30
- which is a 0
in ascii.
这篇关于如何对第 9 个反向引用后的正则表达式进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!