(?!…)
向前识别不等于指定字符就匹配,当下一个单词不等于
例子:
print(‘Isaac(?!Asimov)’)
print(u’abcdAsimovIsaacttttt’)
m=re.findall(u’Isaac(?!Asimov)’,u’abcdAsimovIsaacttttt’)
ifm:
print(m)
print(u’abcdIsaacAsimovttttt’)
m=re.findall(u’Isaac(?!Asimov)’,u’abcdIsaacAsimovttttt’)
ifm:
print(m)
输出结果如下:
Isaac(?!Asimov)
abcdAsimovIsaacttttt
[‘Isaac’]
abcdIsaacAsimovttttt
(?<=…)
向后识别等于指定字符。这里所谓向后,就是已经扫描过的字符。比如
例子:
print(‘(?<=cai)mouse’)
m=re.findall(u'(?<=cai)mouse’,u’caimousemousecaiccaimouse’)
ifm:
print(m)
结果输出如下:
(?<=cai)mouse
[‘mouse’,’mouse’]
(?<!…)
向后识别不等于指定字符。这里所谓向后,就是已经扫描过的字符。比如
例子:
print(‘(?<!cai)mouse’)
m=re.findall(u'(?<!cai)mouse’,u’caimousemousecaiccaimouse’)
ifm:
print(m)
结果输出如下:
(?<!cai)mouse
[‘mouse’]
蔡军生 QQ:9073204 深圳
版权声明:本文为博主原创文章,,未经博主允许不得转载。
当你困难失望的时候,最重要的是事瞧得起你自己;