Regular expression matching everything except a given regular expression

后端 未结 4 1905
[愿得一人]
[愿得一人] 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条回答
  •  我在风中等你
    2020-12-31 08:33

    don't lose your mind with regex.

    if len(mystring) >=4 and mystring[:4]=="mpeg":
        print "do something"
    

    or use startswith() with "not" keyword

    if len(mystring)>=4 and not mystring.startswith("mpeg")
    

提交回复
热议问题