A regex answers a yes or no question – does the string match the pattern.
I want to separate the no’s into two categories:
- invalid strings that are prefixes of valid strings
- invalid strings that are not prefixes of valid
Here’s an example (regular expression 01+2):
-
012is valid -
12is invalid; it is not a prefix of a valid string -
01is invalid; it is a prefix of a valid string:012
Can re do this? If not, is there a library that can make this distinction?
I second the recommendation of regex. The module is simply fantastic.
Here’s an example of fuzzy matching with regex:
The
{d<3}part basically says “if we add one or two chars to that, that would be a match” – the same as point 3. in your question.See http://pypi.python.org/pypi/regex for more info (look for ‘Approximate “fuzzy” matching’).