python爬虫(二十三) 正则表达式分组
text="apple's price $99,orange's price &10" ret=re.match('.*(\$\d+).*(\&\d+)',text) print(ret.group())
取第一组:
text="apple's price $99,orange's price &10" ret=re.match('.*(\$\d+).*(\&\d+)',text) print(ret.group(1))
取第二组:
text="apple's price $99,orange's price &10" ret=re.match('.*(\$\d+).*(\&\d+)',text) print(ret.group(2))
取第一组和第二组:
text="apple's price $99,orange's price &10" ret=re.match('.*(\$\d+).*(\&\d+)',text) print(ret.group(1,2))
取所有得子分组:
text="apple's price $99,orange's price &10" ret=re.match('.*(\$\d+).*(\&\d+)',text) print(ret.groups())