HSH's Blogs

  • Home

  • Tags

  • Categories

  • Archives

Python正则使用

Posted on 2018-07-27 | Edited on 2018-07-29 | In Python

导入正则:re

1
import re

match

1
2
3
4
5
6
7
#match匹配的过程是从左第一个字符向右逐一匹配的,当匹配的过程出现不符合字符时,即停止
匹配过程,相当于匹配表达式中设置了"^"

re.match(pattern,str)

In [34]: re.match(r"aa(\d+?)ddd","aa1234ddd").group(1)
Out[34]: '1234'
Read more »
1…78

黄声焕

71 posts
9 categories
21 tags
© 2019 黄声焕
Powered by Hexo v3.7.1
|
Theme — NexT.Gemini v6.3.0