美文网首页Python语言的奇技淫巧
Python的奇技淫巧(0)---正则表达式

Python的奇技淫巧(0)---正则表达式

作者: 程慕枫 | 来源:发表于2018-06-14 23:20 被阅读0次

正则表达式是一个特殊的字符序列
正则表达式的作用有很多,例如:

定界符

^ : 匹配字符串的开始位置

$ : 匹配字符串的结束位置

  • 正则 : ^123.*123
  • 含义 : 匹配以数字'123'开头且以'123'结尾的字符串
  • 匹配: 123welcome123 , 123shen456zhen123

\b : 匹配一个单词的边界,也就是单词和空格间的位置

  • 正则 : er\b
  • 字符串: teacher Wang
  • 匹配 : 以上字符串可以匹配出er

个数/次数

  • * : 匹配前面的子表达式0次或多次(即任意次)
  • heo , helo , hello , helllo
  • 正则 : hel*o
  • 匹配 : heo , helo , hello , helllo
  • + : 匹配前面的子表达式1次或多次(即至少1次)
  • heo , helo , hello , helllo
  • 正则 : he+o
  • 匹配 : helo , hello , helllo
  • ? : 匹配前面的子表达式0次或1次
  • heo , helo , hello , helllo
  • 正则 : hel?o
  • 匹配 : heo , helo
  • {n} 匹配n次前面的子字符串, n为正整数
  • heo , helo , hello , helllo
  • 正则 : hel{3}
  • 匹配 : helllo

相关文章

  • [转]python正则表达式(一) 函数使用

    原文:python | 史上最全的正则表达式 更全的正则表达式处理函数:在python中使用正则表达式(一) 0....

  • Python的奇技淫巧(0)---正则表达式

    正则表达式是一个特殊的字符序列正则表达式的作用有很多,例如: 定界符 ^ : 匹配字符串的开始位置 $ : 匹配字...

  • 正则表达式

    Python正则表达式初识(一) Python正则表达式初识(二) Python正则表达式初识(三) Python...

  • 正则表达式

    Python:正则表达式Python:正则表达式

  • Python正则表达式指南

    Python正则表达式指南 本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达...

  • 03.编程学习--正则表达式(入门一)

    文:郑元春 人生苦短,我用Python! 0x01:什么是正则表达式 In theoretical compute...

  • 正则的一些故事

    正数的正则表达式(包括0):^[+]{0,1}(\d+) 正数的正则表达式(不包括0):^(?!(0[0-9]{0...

  • Python爬虫(十)_正则表达式

    本篇将介绍python正则表达式,更多内容请参考:【python正则表达式】 什么是正则表达式 正则表达式,又称规...

  • python正则表达式

    本篇将介绍python正则表达式,更多内容请参考:【python正则表达式】 什么是正则表达式 正则表达式,又称规...

  • Python 奇技淫巧

    摘要:Python 奇技淫巧 显示有限的接口到外部 当发布python第三方package时,并不希望代码中所有的...

网友评论

    本文标题:Python的奇技淫巧(0)---正则表达式

    本文链接:https://www.haomeiwen.com/subject/ysweeftx.html