与[duplicate]匹配的正则表达式

问题描述 投票:-3回答:1

此网站不欢迎这个问题。

http-delete
1个回答
0
投票

这与否定的前瞻性是可行的,就像您尝试过的,但不能在字符类中进行:

^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"

因此,本质上,在匹配“行程”之后,我们一次匹配单个字符,同时始终断言我们不在“巴哈马”的开头。

Demo

© www.soinside.com 2019 - 2024. All rights reserved.