Identifying Prefixes Of Regex Matches
I have a module which need to receive some data from a TCP socket, and I have a regular expression which can be used to validate the data I receive. Now I am facing the problem of
Solution 1:
The right search keyword is regular expression partial matches. You can find it here: https://pypi.python.org/pypi/regex
From the doc:
>>>pattern = regex.compile(r'\d{4}')>>># Initially, nothing has been entered:>>>print(pattern.fullmatch('', partial=True))
<regex.Match object; span=(0, 0), match='', partial=True>
>>># An empty string is OK, but it's only a partial match.>>># The user enters a letter:>>>print(pattern.fullmatch('a', partial=True))
None
>>># It'll never match.>>># The user deletes that and enters a digit:>>>print(pattern.fullmatch('1', partial=True))
<regex.Match object; span=(0, 1), match='1', partial=True>
>>># It matches this far, but it's only a partial match.>>># The user enters 2 more digits:>>>print(pattern.fullmatch('123', partial=True))
<regex.Match object; span=(0, 3), match='123', partial=True>
>>># It matches this far, but it's only a partial match.
Post a Comment for "Identifying Prefixes Of Regex Matches"