我想在一个正向后视中使用正向前视,但它似乎不起作用。
我尝试过以下几种方法:(?<=Chapter 1(?=Introduction))(.*)(?=Chapter 2)
全文:
Chapter 1
Introduction
Lorem Ipsum is simply dummy text
Chapter 2
Introduction
Lorem Ipsum is simply dummy text```发布于 2019-10-05 18:58:06
你可以匹配第一章直到介绍,而不是回头看。然后使用具有重复模式的捕获组,该模式检查行是否不是以第2章开头。
^Chapter 1[\r\n]+Introduction[\r\n]+((?:(?!Chapter 2).*(?:\r?\n|$))*)分成部分
^ stringChapter 1[\r\n]+ Start of Introduction[\r\n]+ Match Introduction and 1+ newlines( (?: Match第1章和not (?: (?!Chapter 2).* 2(?:\r?\n|$) string1 not Start with 1+ 1 Non Capture group Capture group
(?!Chapter 2).* Negative lookahead,选中not Start with Chapter 2(?:\r?\n|$) Match a newline or assert end of string
- `)*` Close non capturing group and repeat 0+ times
) Close capture组1如果您想要所有章节的匹配项,您可以在\d中将数字1更改为\d+,将数字2更改为
查看另一个regex demo
https://stackoverflow.com/questions/58245265
复制相似问题