zijue

匹配手机号:

1 phone_str = "hey my name is alex, and my phone number is 13651054607, please call me if you are pretty!"
2 phone_str2 = "hey my name is alex, and my phone number is 18651054604, please call me if you are pretty!"
3  
4 m = re.search("(1)([358]\d{9})",phone_str2)
5 if m:
6     print(m.group())
View Code

匹配IP V4:

1 ip_addr = "inet 192.168.60.223 netmask 0xffffff00 broadcast 192.168.60.255"
2  
3 m = re.search("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", ip_addr)
4  
5 print(m.group())
View Code

分组匹配地址:

contactInfo = \'Oldboy School, Beijing Changping Shahe: 010-8343245\'
match = re.search(r\'(\w+), (\w+): (\S+)\', contactInfo) #分组

match = re.search(r\'(?P<last>\w+), (?P<first>\w+): (?P<phone>\S+)\', contactInfo)
View Code

匹配email:

email = "alex.li@126.com   http://www.oldboyedu.com"
 
m = re.search(r"[0-9.a-z]{0,26}@[0-9.a-z]{0,20}.[0-9a-z]{0,8}", email)
print(m.group())
View Code

 

contactInfo = \'Oldboy School, Beijing Changping Shahe: 010-8343245\'
match = re.search(r\'(\w+), (\w+): (\S+)\', contactInfo) #分组
"""
>>> match.group(1)
  \'Doe\'
  >>> match.group(2)
  \'John\'
  >>> match.group(3)
  \'555-1212\'
"""
match = re.search(r\'(?P<last>\w+), (?P<first>\w+): (?P<phone>\S+)\', contactInfo)

分类:

技术点:

相关文章:

  • 2021-12-14
  • 2021-11-13
  • 2021-12-28
  • 2021-07-11
  • 2021-06-17
  • 2021-12-01
  • 2021-12-18
猜你喜欢
  • 2021-11-23
  • 2021-10-27
  • 2021-09-24
  • 2021-09-25
  • 2021-11-24
  • 2021-11-04
相关资源
相似解决方案