I am totally confused by grouping in python. For example:
import re
m = re.search('From:\s+(.+)\s+To:\s+(.*)\s*', 'From: Toronto To: Beijing')
print m.group(0)
print m.group(1)
print m.group(2)
I can get 3 results after I run this program, but I don't know why I get such results:
From: Toronto To: Beijing
Toronto
Beijing
In addition, sometimes when I use the group method of a match-object I will get a warning saying "no such group".
So, can anyone explain the usage of grouping in regular expressions to me in plain language?