Regular expression matching everything except a given regular expression

后端 未结 4 1886
[愿得一人]
[愿得一人] 2020-12-31 07:39

I am trying to figure out a regular expression which matches any string that doesn\'t start with mpeg. A generalization of this is matching any string which doesn\'t start w

4条回答
  •  -上瘾入骨i
    2020-12-31 08:38

    Your regexp wouldn't match "npeg", I think you would need come up with ^($|[^m]|m($|[^p]|p($|[^e]|e($|[^g])))), which is quite horrible. Another alternative would be ^(.{0,3}$|[^m]|.[^p]|..[^e]|...[^g]) which is only slightly better.

    So I think you should really use a look-ahead assertion as suggested by Dav and Gumbo :-)

提交回复
热议问题