标签:
#!/usr/bin/python
#coding:utf-8
#2015-12-22 11:53:30.469000
"""
"""
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
import re
s = "\t\t1.12 第一节\t36"
pat = r"\t(?=\d+$)"
print re.split(pat,s)
‘‘‘
re.split(pattern, string, maxsplit=0, flags=0)
会用pattern匹配到的字符作为分隔符,对string进行分割,产生一个list,list里没有分割符;
如果pattern里有圆括号(组),分隔符也会作为组出现在结果的list里;
pat = r"\t(?=\d+$)" [‘\t\t1.12 zhang‘, ‘36‘]
匹配到最后一个"\t"
pat = r"\t(\d+$)" [‘\t\t1.12 zhang‘, ‘36‘, ‘‘]
匹配到了最后的"\t"和"36",36在括号里是组,所以显示出来;
pat = r"\t(?:\d+$)" [‘\t\t1.12 zhang‘, ‘‘]
匹配到了"\t36"
‘‘‘
标签:
原文地址:http://www.cnblogs.com/QIAOXINGXING001/p/5114311.html