Python和正则表达式(未完)

来源:互联网 发布:成都移动网络优化中心 编辑:程序博客网 时间:2024/05/22 17:08

 

匹配多个字符串(|)

>>>bt = 'bat|bet|bit'>>>m = re.match(bt, 'bat').group()...'bat'

匹配成功

>>>m = re.match(bt, 'blt').group()...

匹配失败

>>>m = re.match(bt, 'He bit me!).group()...

匹配失败

>>>m.search(bt, 'He bit me!').group()...'bit'

查找到'bit'

匹配任意单个字符( . )

example1:

原创粉丝点击