I'm using Python 2.7.6. I can't understand the following result from re.findall:
>>> re.findall('\d|\(\d,\d\)', '(6,7)')
['(6,7)']
I expected the above to return ['6', '7'], because according to the documentation:
'|'
A|B, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the '|' in this way. This can be used inside groups (see below) as well. As the target string is scanned, REs separated by '|' are tried from left to right. When one pattern completely matches, that branch is accepted. This means that once A matches, B will not be tested further, even if it would produce a longer overall match. In other words, the '|' operator is never greedy. To match a literal '|', use \|, or enclose it inside a character class, as in [|].
Thanks for your help
n [4]: re.findall(r'\d|\d,\d\)', '(6,7)') Out[4]: ['6', '7']Amazing what difference the ( makes, eh? It found a possible match for the second thing first, so that's what got matched. - NightShadeQueen(is more to the left than the first digit. - tobias_k