用于搜索多个单词出现并仅捕获第二个匹配项的正则表达式模式

Regex pattern to search multiple word occurrences and capture the second matched only

我想在 notepad++ 中使用 REGEX 模式捕获第二次出现,即“佛罗里达;西弗吉尼亚;仅 DC。”

 Notepad++
 1 Arkansas; Hawaii; South Dakota; North Carolina
 2 California;Florida; Washington State; New York; Florida; West Virginia; DC
 3 Nevada; Texas; New Mexico; Georgia   


Regex Pattern: '\Florida(.*?)\DC'

Actual Capture: Florida; Washington State; New York; Florida; West Virginia; DC
Desired Capture: Florida; West Virginia; DC  

(?:.*)(Florida.*)对你有用吗?

它“匹配”了一些东西,但只“捕获”了最后一个佛罗里达州和之后的东西。

我在 https://regex101.com/r/cWqhkC/1 测试了这个。

您可以使用否定前瞻断言右侧不再出现佛罗里达。

仅对于匹配,您不需要捕获组。 \F\D 也不必转义。

\bFlorida\b(?!.*\bFlorida\b).*

Regex demo

或者可以选择匹配第一个匹配项,并在捕获组中从第二个匹配项开始捕获。

^(?:.*?\bFlorida\b)?.*?\b(Florida\b.*)

Regex demo