Python正则匹配IP、Url、Mail
2017-02-22 13:50
232 查看
"""
Created on Thu Nov 10 14:07:36 2016
@author: qianzhewoniuqusanbu
"""
import re
def RegularMatchIP(ip):
'''进行正则匹配ip,加re.IGNORECASE是让结果返回bool型'''
pattern=re.match(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]?)$',ip,re.IGNORECASE)
if pattern:
print ip
else:
print "The IP address format is incorrect!"
def RegularMatchUrl(url):
pattern=re.match(r'(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?',url,re.IGNORECASE)
if pattern:
print url
else:
print "invalid url"
def RegularMatchEmail(email):
pattern=re.match(r'\w+@([0-9a-zA-Z]+[-0-9a-zA-Z]*)(\.[0-9a-zA-Z]+[-0-9a-zA-Z]*)+',email,re.IGNORECASE)
if pattern:
print email
else:
print "invalid eamil"
RegularMatchIP("12.32.35.23")
RegularMatchUrl("http://c.biancheng.net/cpp/html/1435.html")
RegularMatchEmail("109823434@qq.com")
Created on Thu Nov 10 14:07:36 2016
@author: qianzhewoniuqusanbu
"""
import re
def RegularMatchIP(ip):
'''进行正则匹配ip,加re.IGNORECASE是让结果返回bool型'''
pattern=re.match(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]?)$',ip,re.IGNORECASE)
if pattern:
print ip
else:
print "The IP address format is incorrect!"
def RegularMatchUrl(url):
pattern=re.match(r'(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?',url,re.IGNORECASE)
if pattern:
print url
else:
print "invalid url"
def RegularMatchEmail(email):
pattern=re.match(r'\w+@([0-9a-zA-Z]+[-0-9a-zA-Z]*)(\.[0-9a-zA-Z]+[-0-9a-zA-Z]*)+',email,re.IGNORECASE)
if pattern:
print email
else:
print "invalid eamil"
RegularMatchIP("12.32.35.23")
RegularMatchUrl("http://c.biancheng.net/cpp/html/1435.html")
RegularMatchEmail("109823434@qq.com")
相关文章推荐
- python 正则匹配电话与ip
- Python中匹配IP的正则表达式
- python匹配ip正则
- python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL
- python re正则匹配网页中图片url地址
- python匹配ip正则
- Python 正则表达式匹配ip格式详解
- Python中匹配IP的正则表达式
- Python 匹配任意字符(包括换行符)的正则表达式写法
- 匹配IP字串、域名的正则表达式
- Python正则表达式的几种匹配用法
- 匹配IP字串、域名的正则表达式
- Python:正则表达式匹配任意字符(包括换行符)的写法
- Python正则表达式的用法(1. 匹配)
- Python中正则表达式对中文的匹配问题
- javascript 正则表达式 一个 匹配和解析url的
- python非贪婪、多行匹配正则表达式例子[转载]
- Python正则表达式的常用匹配用法
- java获取url内容及正则匹配链接图片地址
- PHP下ereg实现匹配ip的正则