网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

如何使用PYTHON里的re.compile()

时间:2024-10-13 06:36:20

1、打开JUPYTER NOTEBOOK,新建一个PY文档。

如何使用PYTHON里的re.compile()

3、aRegex = re.compile(r'\d\d\d-\d\d\d\d-\d\d\d\d')首先我们要测试在字符串里面找到\d\d\d-\d\d\d\d-\d\d\d\d的文本。\d表示数字,0到。

如何使用PYTHON里的re.compile()

5、aRegex = re.compile(r'(\d\d\d)-(\d\d\d\d)-(\d\d\d\颊俄岿髭d)')text = "I have a phone and the phone number is 159-9999-9999."find = aRegex.search(text)find.group(1)find.group(2)find.group(3)find.group(0)find.group()找到的结果可以以组的形式展现出来,我们可以选择打印相应的组,用数字来找到即可。

如何使用PYTHON里的re.compile()

7、text = "The number is (010)110-112."bRegex = re.compile(r'(\(\d\d\d\))(\d\d\d-\d\d\d)')find1 = bRegex.search(text)find1.group(1)find1.group(2)find1.group()如果我们要找到的格式里有括号,那么要\(,\)来表示。不然会出错。

如何使用PYTHON里的re.compile()
© 2025 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com