fork download
  1. import re
  2.  
  3. rex = re.compile(r'^([^\\]*)(\\.[^.^$*+?{}\[\]|()\\]*)*[.^$*+?{}\[\]|()]', re.MULTILINE)
  4.  
  5. arr = [r"example", r"foo\.bar", r"e.ample", r"foo\\.bar", r"foo\\bar\.baz", r"foo\\bar.baz", r"foo(bar)"]
  6.  
  7. for s in arr:
  8. print s, re.search(rex, s) != None
  9.  
  10.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
example False
foo\.bar False
e.ample True
foo\\.bar True
foo\\bar\.baz False
foo\\bar.baz True
foo(bar) True