I made a few tests to help myself to understand non-greedy in Python, but it made me much more confused than before. Thank you for the help!
lan='From 000@hhhaaa@stephen.marquard@uct.ac.za@bbb@ccc fff@ddd eee'
print(re.findall('\S+@\S+?',lan)) # 1
print(re.findall('\S+@\S+',lan)) # 2
print(re.findall('\S+?@\S+?',lan)) # 3
print(re.findall('\S+?@\S+',lan)) # 4
Result:
['000@hhhaaa@stephen.marquard@uct.ac.za@bbb@c', 'fff@d'] # 1
['000@hhhaaa@stephen.marquard@uct.ac.za@bbb@ccc', 'fff@ddd'] # 2
['000@h', 'hhaaa@s', 'tephen.marquard@u', 'ct.ac.za@b', 'bb@c', 'fff@d'] # 3
['000@hhhaaa@stephen.marquard@uct.ac.za@bbb@ccc', 'fff@ddd'] # 4
Question:
- why result only shows one d here - @d?
- is normal, very clear.
- very confusing, I even do not know how to ask the logic behind... Especially when compared with 1...
- it seems it is same as 2, so why ? before @ is so 'weak'?