Problem:
m = Re.findall (' [0-9]*4[0-9]* ', ' [4] ')
can match to 4.
m = Re.findall (' ([0-9]) ([0-9]) * ', ' [4] ')
Matches 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 indicate a sequence of matching.
To add, when I put it in notepad++, both types of writing can be matched, and I don't know why Python is out of the question.
Answer:
The Python's regular () matches, so the return result is [', '], which is the match in two (). To achieve the original matching effect, is to match 4 out, there are two ways to solve:
1. Add a brace to the outermost layer to: M = Re.findall (' ([[0-9]) ([0-9]) ', ' [4] '), the first element of the returned result is the matching result.
2. Remove () The match result returned, in front of parentheses to add?:, Into M = Re.findall (?: \ d) (?: \ d) * ', ' [4] ', return result is to match the result.