此网站不欢迎这个问题。
这与否定的前瞻性是可行的,就像您尝试过的,但不能在字符类中进行:
^trip(?:(?!bahamas).)*$
说明:
^trip # match trip at the beginning
(?: )*$ # whatever's in this group, until the end of the line (non-capturing)
(?!bahamas). # any character, unless it's the start of "bahamas"
因此,本质上,在匹配“行程”之后,我们一次匹配单个字符,同时始终断言我们不在“巴哈马”的开头。