如何使用前瞻进行分组和引用

发布于 2024-11-18 14:08:11 字数 538 浏览 5 评论 0原文

在此示例中:

("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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2024-11-25 14:08:11

只需将它们称为 \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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文