概念
- 使用单个字符串来描述匹配一系列符合某个句法规则的字符串
- 是对字符串操作的一种逻辑公示
- 应用场景:处理文本和数据
- 正则表达式过程:依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功;否则匹配失败。
Python - re模块
re.compile(r'imooc') pattern.match('imooc python')
r'imoor' -> Pattern -> Match -> Result
![](https://img.haomeiwen.com/i2029557/0aa5d9b9adc06d50.png)
pa = re.compile(r'imooc', re.IGNORECASE) //re.INGORECASE 可以简写 为re.I
ma = pa.match('Imooc python')
ma.group()
正则表达式的基本语法
![](https://img.haomeiwen.com/i2029557/168622aca9bd1bd7.png)
![](https://img.haomeiwen.com/i2029557/ff6d4413e3f2ab9c.png)
![](https://img.haomeiwen.com/i2029557/d25a337f6b0ff41f.png)
![](https://img.haomeiwen.com/i2029557/e91671e8c04d9c28.png)
re模块中的其他方法
![](https://img.haomeiwen.com/i2029557/c52b52c31529fd3c.png)
![](https://img.haomeiwen.com/i2029557/8bf0eb94d71d2e2c.png)
网友评论