python 正则表达式 匹配指定字符

比如 line = "result of fold 0, instance 3.";

有时候你只要 里面的0, 或者 3 , 怎么办?

只要在正则表达式中加个括号:

pattern = re.compile(r'.?instance.?(\w).')

 

用括号 \w , 那么group(1)就会只有3这个数字;

posted on 2017-04-03 16:29  Lirh_china  阅读(2060)  评论(0编辑  收藏  举报

导航