>>> m = re.search(r'^(\d{3,4}-)?(\d{7,8})$','020-82228888')
>>> m.group(0)
'020-82228888'
>>> m.group(1)
'020-'
>>> m.group(2)
'82228888'
>>> re.findall(r'(\d{3,4}-)?(\d{7,8})','020-82228888\n0357-4227865')
[('020-', '82228888'), ('0357-', '4227865')]
>>> re.findall(r'(?:\d{3,4}-)?\d{7,8}','020-82228888\n0357-4227865')
['020-82228888', '0357-4227865']
>>> re.findall(r'(?:\d{3,4}-)?\d{7,8}','020-82228888\n4227865')
['020-82228888', '4227865']
>>> sentence = """You said "why?" and I say "I don't know"."""
>>> re.findall(r'["\'](.*?)["\']', sentence)
['why?', 'I don']
>>> re.findall(r'(["\'])(.*?)\1', sentence)
[('"', 'why?'), ('"', "I don't know")]
>>> sentence = "from 12/22/1629 to 11/14/1643"
>>> re.sub(r'(?P<month>\d{2})/(?P<day>\d{2})/(?P<year>\d{4})', r'\g<year>-\g<month>-\g<day>', sentence)
'from 1629-12-22 to 1643-11-14'
>>> sentence = """You said "why?" and I say "I don't know"."""
>>> re.findall(r'(?P<quote>["\'])(.*?)\g<quote>', sentence)
[]
>>> re.search(r'(?P<quote>["\'])(.*?)\g<quote>', sentence)
>>> re.search(r'(?P<quote>["\'])(.*?)\1', sentence)
<_sre.SRE_Match object; span=(9, 15), match='"why?"'>
>>> re.search(r'(?P<quote>["\'])(.*?)\1', sentence).groupdict()
{'quote': '"'}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有