python正则表达式使用
生活随笔
收集整理的這篇文章主要介紹了
python正则表达式使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
模板代碼:
import re #python 自1.5版本增加了re模塊,它提供了Perl風(fēng)格的正則表達(dá)式模式 print(re.match('www', 'www.baidu.com').span()) #在起初位置匹配 line = "Cats are smarter than dogs" matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I) if matchObj:ms = matchObj.groups()for m in ms:print(m)輸出:
(0, 3) Cats smarter?
總結(jié)
以上是生活随笔為你收集整理的python正则表达式使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsoup的Elements类
- 下一篇: Mybatis介绍、jdbc操作数据库原