Python正则表达式急速入门
|
匹配模式
说明
上述六种模式在实际开发中很少用到,我们只需要了解即可。 使用 compile 很简单,如下: import re pattern = re.compile(r'd') 2.matchmatch 的作用是利用 Pattern 实例,从字符串左侧开始匹配,如果匹配到就返回一个 Match 实例,如果没有匹配到就返回 None。 import re def getMatch(message): pattern = re.compile(r'(d{4}[-年])(d{2}[-月])(d{2}日{0,1})') match = re.match(pattern, message) if match: print(match.groups()) for item in match.groups(): print(item) else: print("没匹配上") if __name__ == '__main__': message = "2019年01月23日大会开始" getMatch(message) message = "会议于2019-01-23召开" (编辑:三门峡站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- iPhone 6s国内上市时间曝光:首发推迟一周
- iOS 8.1.1正式版发布 iPhone 4S和iPad 2性能显著提升
- Apple Pay新增支持哪三家银行 Apple Pay还会新增支持哪些银
- 最低7699元!京东这些RTX系显卡游戏本贼便宜
- Flex 事件分发(FlexViewer事件机制)剥离过程
- 开源操作系统Unix SunOS 4.1.1上手体验
- KIMOJI卡戴珊表情是什么_KIMOJI卡戴珊表情是真的吗
- iPad Pro的True Tone显示屏是什么 什么是True Tone显示技术
- 游戏办公一网打尽 超值戴尔笔记本推荐
- IBM Workload Partitions Manager和Live Application Mobil
