hldh214's blog

Home Archives
2016-11-09

Python 强大的模式匹配

一些很 sb 的正则需求, 对子模式要求苛刻
不同情况的子模式顺序不同
这就要用到命名的子模式了

1
2
3
4
5
6
7
8
9
import re

regex = re.match(r'(?P<first>\d+)qwe(?P<last>\d+)', '123qwe321')

print(regex.group(1))
print(regex.group('first'))
print(regex.group(2))
print(regex.group('last'))

1
2
3
4
5
6
7
8
C:\Python34\python.exe E:/python/tmp.py
123
123
321
321

Process finished with exit code 0

Share Comments
Newer
Git 强大的二分 debug 功能 - git bisect
Older
PHPUnit 学习乱记

Tags

  • Android
  • Crawler
  • Git
  • HomeAutomation
  • Interview
  • Linux
  • Steam

Tag Cloud

Android Crawler Git HomeAutomation Interview Linux Steam

Archives

  • 八月 2023
  • 七月 2022
  • 三月 2022
  • 二月 2022
  • 十一月 2021
  • 三月 2021
  • 一月 2021
  • 七月 2020
  • 三月 2019
  • 二月 2019
  • 一月 2019
  • 十二月 2018
  • 十一月 2018
  • 九月 2018
  • 八月 2018
  • 六月 2018
  • 四月 2018
  • 三月 2018
  • 二月 2018
  • 八月 2017
  • 七月 2017
  • 三月 2017
  • 二月 2017
  • 十二月 2016
  • 十一月 2016
  • 八月 2016
  • 七月 2016
  • 六月 2016
  • 五月 2016
  • 四月 2016
  • 二月 2016
  • 十二月 2015

Recent Posts

  • 别让扫地机器人成为云端奴隶,Valetudo 助你夺回控制权
  • 你管这叫全屋智能???
  • Buildroot 2018.02 升级 2022.02 小记
  • 對呀對呀!……回字有四樣寫法,你知道麼?
  • 磁盘扩容二三事

friends

  • BlaWhickte(BigDickGirl)
  • 汀雨(谷歌扛把子)
  • 李春燕(会口算MD5的黑客)
  • 白菜爷爷(PHP滞销书作者)
  • 天南总(CTO)
© 2023 Jim
Powered by Hexo
Home Archives