0
点赞
收藏
分享

微信扫一扫

33 - 用正则表达式判断字符串中是否包含日期


1. 请简要描述Python正则表达式中match函数的作用

import re

print(re.match('.*hello', 'ahello'))

<re.Match object; span=(0, 6), match='ahello'>

2. 如果日期的格式是4位年,2位月,2位日(如2012-01-02) ,如何使用正则表达式判断一个字符串中是否包含这样的日期

s = 'Today is 2020-02-21.'
m = re.match('.*\d{4}-\d{2}-\d{2}.*', s)

if m is not None:
print(m.group())

Today is 2020-02-21.

34 - 寻找字符串中的手机号


举报

相关推荐

0 条评论