Problem:
m = Re.findall (' [0-9]*4[0-9]* ', ' [4] ')
can match to 4.
m = Re.findall (' ([0-9]) *4 ([0-9]) * ', ' [4] ')
Match less than 4.
What is this for? PS, this is a simplified description, I want to use a more complex than this, so to use (), to represent a sequence of matches.
To add, when I put it in the notepad++, both of them could be matched, and I don't know why Python doesn't.
Answer:
Python's regular use () will match, so the return result is [', '], is a match in two (). To achieve the original matching effect, is to match the 4 out, there are two ways to solve:
1. The outermost bracket, which becomes: M = Re.findall (([0-9]) *4 ([0-9]) *, "[4]"), returns the first element of the result that matches the result.
2. Remove () The match result returns, joins before the parenthesis:, becomes m = Re.findall ('?: \ d) *4 (?: \ d) * ', ' [4] ', return the result is the result to match.