如何使用前瞻进行分组和引用
在此示例中:
("Talking with Bengt Holmstrom 1" "#44")
("Chapter 1 What is Economics? 3" "#46")
,由正则表达式 ^(?!.*(Chapter|Part)).*\n\("Chapter.*\n
) 匹配,我想 有两个组 ("Talking with Bengt Holmstrom 1" "#44")
和 ("Chapter 1 What is Economics? 3" "#46")
。
为了分组,上面的正则表达式修改为^((?!.*(Chapter|Part)).*)\n(\("Chapter.*)\n
。我想参考到这两个组,但使用 \1
和 \2
作为它们的引用,如 \1\2
不起作用,我想知道。 如果有什么问题吗?
顺便说一句,我正在使用 gedit, 插件。
正则表达式
In this example:
("Talking with Bengt Holmstrom 1" "#44")
("Chapter 1 What is Economics? 3" "#46")
, which is matched by regex ^(?!.*(Chapter|Part)).*\n\("Chapter.*\n
, I would like to
have two groups ("Talking with Bengt Holmstrom 1" "#44")
and ("Chapter 1 What is Economics? 3" "#46")
.
To group, the above regex is modified to be^((?!.*(Chapter|Part)).*)\n(\("Chapter.*)\n
. I want to refer to the two groups, but using \1
and \2
as their references as in \1\2
doesn't work. I was wondering if anything is wrong?
BTW, I am using gedit regex plugin.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将它们称为 \1 和 \3 即可。
只需数一下开头(从左到右。1)就是
((?!.*(Chapter|Part)).*)
,所以第一行。 2) 是(Chapter|Part)
3) 是("Chapter.*)
,所以第二行以 "Chapter.*) 开头。请注意,作为前瞻开头的 ( 不计算在内。
Just refer to them as \1 and \3.
Just count the opening ( as you go from left to right. 1) is
((?!.*(Chapter|Part)).*)
, so the first line. 2) is(Chapter|Part)
3) is("Chapter.*)
, so the second line starting with "Chapter.Note that the ( that is the beginning of the lookahead is not counted.