Commit 60d2c4a4 by bonnieyan

Update regular.py

parent 51370c36
...@@ -3,34 +3,38 @@ import re ...@@ -3,34 +3,38 @@ import re
class Regular: class Regular:
def __init__(self, s):
self.s = s
# 方法能够匹配出所有的数字 # 方法能够匹配出所有的数字
def get_numbers(self, s): def get_numbers(self):
print(re.findall("\d{4,7}", s)) print(re.findall("\d{3,11}", s))
# 方法能够匹配出所有的邮箱 # 方法能够匹配出所有的邮箱
def get_emails(self, s1): def get_emails(self):
print(re.findall("\d*@[a-z0-9]*.com", s1)) print(re.findall("\d*@[a-z0-9]*.com", s))
# 方法可以匹配出所有的ip # 方法可以匹配出所有的ip
def get_ips(self, s2): def get_ips(self):
print(re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", s2)) print(re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", s))
# 方法能够匹配出所有的电话号码,电话包含座机和移动电话,座机要考虑区号3位或4位,号码要考虑7位或8位 # 方法能够匹配出所有的电话号码,电话包含座机和移动电话,座机要考虑区号3位或4位,号码要考虑7位或8位
def get_phone_numbers(self,s3): def get_phone_numbers(self):
print(re.findall("0\d{2,3}-\d{7,8}|13[0-9]\d{8}|17[0-9]\d{8}", s3)) print(re.findall("0\d{2,3}-\d{7,8}|13[0-9]\d{8}|17[0-9]\d{8}", s))
# 方法能够匹配出所有的url,url可以以http开头、https开头、ftp开头 # 方法能够匹配出所有的url,url可以以http开头、https开头、ftp开头
def get_urls(self, s4): def get_urls(self):
print(re.findall("http://w{3}.[a-z]*.com|https://w{3}.[a-z]*.com|ftp://w{3}.[a-z]*.com", s4)) print(re.findall("http://w{3}.[a-z]*.com|https://w{3}.[a-z]*.com|ftp://w{3}.[a-z]*.com", s))
s = "给的一串数字1231,是不是哦1778881" s = "给的一串数字1231,是不是哦1778881;" \
s1 = "我的邮箱是:525663314@qq.com,她的邮箱是:1738022131@126.com" "我的邮箱是:525663314@qq.com,她的邮箱是:1738022131@126.com;" \
s2 = "ip地址是:1132.1112.312.1,123.124.121.122,10.112.123.122" "ip地址是:1132.1112.312.1,123.124.121.122,10.112.123.122;" \
s3 = "我的电话号码是:010-12341213,0832-3821251,17380409735,12345678901" "我的电话号码是:010-12341213,0832-3821251,17380409735,12345678901" \
s4 = "以下url为:http://www.baidu.com,https://www.tmall.com,ftp://www.taobao.com" "以下url为:http://www.baidu.com,https://www.tmall.com,ftp://www.taobao.com"
p = Regular() p = Regular(s)
p.get_numbers(s) p.get_numbers()
p.get_emails(s1) p.get_emails()
p.get_ips(s2) p.get_ips()
p.get_phone_numbers(s3) p.get_phone_numbers()
p.get_urls(s4) p.get_urls()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment