说明:本文实例总结了Python正则表达式常用函数。分享给大家供大家参考,具体如下:
re.match()
函数原型:
match(pattern, string, flags=0)
Try to apply the pattern at the start of the string,
returning a match object, or None if no match was found.
函数作用:
re.match函数尝试从字符串的开头开始匹配一个模式,如果匹配成功,返 <weixin_38690089> 上传 | 大小:83kb
说明:本文实例讲述了python判断字符串是否包含子字符串的方法。分享给大家供大家参考。具体如下:
python的string对象没有contains方法,不用使用string.contains的方法判断是否包含子字符串,但是python有更简单的方法来替换contains函数。
方法1:使用 in 方法实现contains的功能:
site = '//www.jb51.net/'
if "jb51" in site:
print('site contains jb51')
输出结果:sit <weixin_38622427> 上传 | 大小:32kb