I have a list of regexes from which I want to extract those that are equivalent to a string comparison.
For example, those regexes are equivalent to a simple string comparison:
[r"example", # No metacharacters
r"foo\.bar"] # . is not a metacharacter because it is escaped
while those regexes are not:
[r"e.ample", # . is a metacharacter
r"foo\\.bar"] # . is a metacharacter because it is not escaped
According to https://docs.python.org/2/howto/regex.html, the list of valid metacharacters is . ^ $ * + ? { } [ ] \ | ( )
.
I'm about to build a regex, but it looks to be a bit complicated. I'm wondering if there's a shortcut by examining the re
object or something.