我尝试为一小段术语进行匹配,这些术语可以从1(通常)到几次发生并提取每个术语。而不是制作一个复杂的正则表达式,匹配每个匹配的匹配项,我认为可能有一种方法可以使用正则表达式:
测试数据:
offices in NY
offices in NY and CA
offices in NY, CA and NJ
offices in NY, CA, and NJ
offices in NY and CA and NJ
offices in NY/CA/NJ
offices in NY, CA, NJ, DE
正则表达式我尝试过:
/offices in (?<ST>(NY|CA|NJ|DE))/
答案 0 :(得分:0)
看起来hwnd得到了答案:
(?:offices in|\G(?<!^)(?:(?!NY|CA|NJ|DE).)*) *(?<ST>(?:NY|CA|NJ|DE))