概述
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import
re
import
sys
def
getIPAddFromFile
(
fobj
):
regex
=
re
.
compile
(
r
'b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b'
,
re
.
IGNORECASE
)
ipadds
=
re
.
findall
(
regex
,
fobj
)
print
ipadds
return
ipadds
def
getPhoneNumFromFile
(
fobj
):
regex
=
re
.
compile
(
r
'1d{10}'
,
re
.
IGNORECASE
)
phonenums
=
re
.
findall
(
regex
,
fobj
)
print
phonenums
return
phonenums
def
getMailAddFromFile
(
fobj
):
regex
=
re
.
compile
(
r
"b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}b"
,
re
.
IGNORECASE
)
mails
=
re
.
findall
(
regex
,
fobj
)
print
mails
return
mails
def
getUrlFromFile
(
fobj
):
regex
=
re
.
compile
(
r
"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
,
re
.
IGNORECASE
)
urls
=
regex
.
findall
(
fobj
)
print
urls
return
urls
def
main
(
FilefilePath
):
fobj
=
open
(
FilefilePath
,
'rb'
).
read
()
urllist
=
getUrlFromFile
(
fobj
)
mailList
=
getMailAddFromFile
(
fobj
)
phoneNum
=
getPhoneNumFromFile
(
fobj
)
ipaddlist
=
getIPAddFromFile
(
fobj
)
if
__name__
==
'__main__'
:
main
(
sys
.
argv
[
1
])
最后
以上就是体贴大炮为你收集整理的python正则表达式获取网址、IP、手机号、邮箱的全部内容,希望文章能够帮你解决python正则表达式获取网址、IP、手机号、邮箱所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复