Python re “bogus escape error”

后端 未结 4 2003
梦毁少年i
梦毁少年i 2020-12-08 23:32

I\'ve been messing around with the python re modules .search method. cur is the input from a Tkinter entry widget. Whenever I enter a \"\\\

4条回答
  •  北海茫月
    2020-12-08 23:52

    If you are trying to search for "cur" in "tup[0]" you should do this through "try:... except:..." block to catch invalid pattern:

    try :
        se = re.search(cur, tup[0], flags=re.IGNORECASE)
    except re.error, e:
        # print to stdout or any status widget in your gui
        print "Your search pattern is not valid."
        # Some details for error:
        print e
        # Or some other code for default action.
    

提交回复
热议问题