Skip to content

Instantly share code, notes, and snippets.

@bdw
Created March 25, 2014 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdw/9762661 to your computer and use it in GitHub Desktop.
Save bdw/9762661 to your computer and use it in GitHub Desktop.
showing python re is subtly broken
#!/usr/bin/env python
import re
s = r'"foo \" bar" baz "quix"'
# same regex right?
p_a = r'"(\\"|[^"])*"'
p_b = r'"([^"]|\\")*"'
# no
print(re.match(p_a, s).group(0))
print(re.match(p_b, s).group(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment