正则表达式库re是非常重要的一个库。

首先正则表达式有两种表示类型,一种是raw string类型(原生字符串类型),也就是我们经常看到的r'  '的写法,另一种是不带r的写法,称为string类型。raw string的作用是把转义字符当做普通的字符,所以一般来说,我们都是使用raw string类型,这样会更为方便。

 

接下来介绍re库的主要方法:

python学习之re库

 

1、re.search()

python学习之re库

 python学习之re库

python学习之re库

 

2、re.match()

python学习之re库

python学习之re库

 

3、re.findall()

python学习之re库

python学习之re库

 

4、re.split()

python学习之re库

python学习之re库

 

5、re.finditer()

python学习之re库

python学习之re库

 

6、re.sub()

python学习之re库

python学习之re库

 

7、re.compiler()使用

python学习之re库

 

在上面的方法中,有些方法返回的是match对象,那么什么是match对象呢?

match对象的属性有如下:

python学习之re库

match对象的方法有如下:

python学习之re库

 

python学习之re库

 

相关文章:

  • 2021-05-10
  • 2021-07-02
  • 2021-07-18
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案