具有 space 个字符的正则表达式后视词

regext lookbehind word having space-characters

我正在尝试在 join and on 之间获取 table 名称 course。两者之间可以有任何 space 字符。

我应用了以下 returns spaces+course 的正则表达式。我试过 (?<=join\s+)(\w+)(?=.*on) 但问题是它说 lookbehind needs to be zero width

(?<=join)\s+(\w+)(?=.*on)

left outer join      course c on s.id = c.id

https://regex101.com/r/bT9hG1/1

由于 sublime text editor 使用 PCRE 正则表达式,您可以使用 \K 重置匹配信息:

(?<=join\s)\s*\K(\w+)\b(?=.*on)

或者在您的情况下,您可以在不使用 \b & \s

的情况下使用以下表达式
(?<=join)\s+\K(\w+)(?=.+ on )

RegEx Demo

\K 重置报告匹配的起点。任何先前消耗的字符不再包含在最终匹配中。