分析
数字中经常是3个数字一组,之后跟一个逗号,因此规律为:,,***
正则式
复制代码 代码如下:
[a-z]+,[a-z]?
复制代码 代码如下:
import re
sen = "abc,123,456,789,mnp"
p = re.compile("\d+,\d+?")
for com in p.finditer(sen):
mm = com.group()
print "hi:", mm
print "sen_before:", sen
sen = sen.replace(mm, mm.replace(",", ""))
print "sen_back:", sen, '\n'
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8