您需要包含点作为要排除的字符。由于.是正则表达式中的控制字符,因此必须对其进行转义:^((?!apple|\.).)*$在这种情况下,我们告诉它匹配 0 个或多个任何字符,只要没有匹配 'apple' 或 '.' 的模式。字符串中的任何位置。这个表达式可以解构如下:^ = Start of string( = Start of capture group( = Start of capture group?! = Negative Look aheadapple = First thing to look for| = Logical Or\. = Match a literal . character) = End of capture group. = Match any character) = End of capture group* = Match zero or more$ = End of String