python培训之re.match函数的使用

发布时间:2022-12-17 09:42:14 人气:110 作者:多测师

  python re.match函数的使用

  1、从字符串的起始位置匹配正则表达式,re.match函数从string的起始位置开始匹配。

  2、如果匹配失败则返回None,匹配成功则返回匹配到的字符串。

  pattern是正则表达式,string是要匹配的字符串,flags是标志位。

  re.match函数从string的起始位置开始匹配。

python培训之re.match函数的使用

  实例

  import re

  x=re.match("[1-9]\d*","123abd")

  if x!=None:

  print(x.group())

  else:

  print("none")

  y=re.match("[1-9]\d*","c123ad")

  if y!=None:

  print(y.group())

  else:

  print("none")

  #输出结果:

  123

  none

  以上就是python re.match函数的使用,希望对大家有所帮助。更多Python学习指路:请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线