【Rollo的Python之路】Python 正则表达式 学习笔记

Python3 正则表达式:

正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配.

字符串也有很多表达式,可以查找,替换,拆分:

s = 'hello world'
print(s.find('llo'))

print(s.replace('ll','xx'))

print(s.split('l'))

执行结果:

2
hexxo world
['he', '', 'o wor', 'd']

  

  string提供的方法是完全匹配,正则表达式用来模糊匹配的。

 

  元字符:“.”, “*” , “?”,"$", "+","|","\","^"

 

posted @ 2019-05-06 10:30  Rollo|St  阅读(134)  评论(0编辑  收藏  举报