Discuss / Python / group和groups属性

group和groups属性

Topic source

zhu_weimin123

#1 Created at ... [Delete] [Delete and Lock User]

group属性

def name_of_email(addr): if '<' in addr: res=re.match(r'(^<[\w]+\s[\w]+>)',addr).group() return res[1:-1] else: res=re.match(r'(^[\w]+@)',addr).group() return res[:-1] groups属性 defn name_of_email(addr): if '<" in addr: res=re.match(r'(<[\w]+\s[\w]+>)',addr).groups() return res[0][1:-1] else: res=re/match(r'(^[\w]+@)',addr).groups() reutrn res[:-1]

#group(N)是返回配对的第N个括号内容,group()-group()返回整个配对内容,不分括号;
#groups()是将配对内容返回一个turple。

  • 1

Reply