Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1-homework-yanjun
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bonnieyan
1-homework-yanjun
Commits
60d2c4a4
Commit
60d2c4a4
authored
Jan 15, 2019
by
bonnieyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update regular.py
parent
51370c36
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
5-homework-yanjun/regular.py
+27
-24
No files found.
5-homework-yanjun/regular.py
View file @
60d2c4a4
...
...
@@ -3,34 +3,38 @@ import re
class
Regular
:
def
__init__
(
self
,
s
):
self
.
s
=
s
# 方法能够匹配出所有的数字
def
get_numbers
(
self
,
s
):
print
(
re
.
findall
(
"
\
d{
4,7
}"
,
s
))
def
get_numbers
(
self
):
print
(
re
.
findall
(
"
\
d{
3,11
}"
,
s
))
# 方法能够匹配出所有的邮箱
def
get_emails
(
self
,
s1
):
print
(
re
.
findall
(
"
\
d*@[a-z0-9]*.com"
,
s1
))
def
get_emails
(
self
):
print
(
re
.
findall
(
"
\
d*@[a-z0-9]*.com"
,
s
))
# 方法可以匹配出所有的ip
def
get_ips
(
self
,
s2
):
print
(
re
.
findall
(
"
\
d{1,3}
\
.
\
d{1,3}
\
.
\
d{1,3}
\
.
\
d{1,3}"
,
s
2
))
def
get_ips
(
self
):
print
(
re
.
findall
(
"
\
d{1,3}
\
.
\
d{1,3}
\
.
\
d{1,3}
\
.
\
d{1,3}"
,
s
))
# 方法能够匹配出所有的电话号码,电话包含座机和移动电话,座机要考虑区号3位或4位,号码要考虑7位或8位
def
get_phone_numbers
(
self
,
s3
):
print
(
re
.
findall
(
"0
\
d{2,3}-
\
d{7,8}|13[0-9]
\
d{8}|17[0-9]
\
d{8}"
,
s
3
))
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}"
,
s
))
# 方法能够匹配出所有的url,url可以以http开头、https开头、ftp开头
def
get_urls
(
self
,
s4
):
print
(
re
.
findall
(
"http://w{3}.[a-z]*.com|https://w{3}.[a-z]*.com|ftp://w{3}.[a-z]*.com"
,
s4
))
s
=
"给的一串数字1231,是不是哦1778881"
s1
=
"我的邮箱是:525663314@qq.com,她的邮箱是:1738022131@126.com"
s2
=
"ip地址是:1132.1112.312.1,123.124.121.122,10.112.123.122"
s3
=
"我的电话号码是:010-12341213,0832-3821251,17380409735,12345678901"
s4
=
"以下url为:http://www.baidu.com,https://www.tmall.com,ftp://www.taobao.com"
p
=
Regular
()
p
.
get_numbers
(
s
)
p
.
get_emails
(
s1
)
p
.
get_ips
(
s2
)
p
.
get_phone_numbers
(
s3
)
p
.
get_urls
(
s4
)
\ No newline at end of file
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"
,
s
))
s
=
"给的一串数字1231,是不是哦1778881;"
\
"我的邮箱是:525663314@qq.com,她的邮箱是:1738022131@126.com;"
\
"ip地址是:1132.1112.312.1,123.124.121.122,10.112.123.122;"
\
"我的电话号码是:010-12341213,0832-3821251,17380409735,12345678901"
\
"以下url为:http://www.baidu.com,https://www.tmall.com,ftp://www.taobao.com"
p
=
Regular
(
s
)
p
.
get_numbers
()
p
.
get_emails
()
p
.
get_ips
()
p
.
get_phone_numbers
()
p
.
get_urls
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment