1

在这个例子中:

("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. 我想引用这两个组,但是像 in 那样使用\1and\2作为他们的引用是\1\2行不通的。我想知道有什么问题吗?

顺便说一句,我正在使用 gedit 正则表达式插件。

谢谢!

4

1 回答 1

1

只需将它们称为 \1 和 \3。

只需计算开头(从左到右。1)就是((?!.*(Chapter|Part)).*),所以第一行。2) is (Chapter|Part)3) is ("Chapter.*),所以第二行以“Chapter.

请注意,作为先行开始的 ( 不计算在内。

于 2011-07-05T00:23:35.483 回答