python 判断字符串是否为(或包含)IP地址
- 下面是某个字符串是否为IP地址
import re- def isIP(str):
p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
if p.match(str):
return True
else:
return False
myStr = "10.69.36.95"
if isIP(myStr):
print(myStr,"it is a IP!")
else:
print(myStr, "it is not a IP!")
- 下面是某个字符串是否包含IP地址(两种方法分别进行判断)
- import re
def ip_exist_two(one_url):
compile_rule = re.compile(r'(?<![\.\d])(?:\d{1,3}\.){3}\d{1,3}(?![\.\d])')
match_list = re.findall(compile_rule, one_url)
if match_list:
print (match_list)
else:
print('missing................')
def ip_exist_one(one_url):
compile_rule = re.compile(r'\d+[\.]\d+[\.]\d+[\.]\d+')
match_list = re.findall(compile_rule, one_url)
if match_list:
print( match_list)
else:
print ('missing................')
if __name__ == '__main__':
ip_list = ['http://101.23.45.67/sd/sd.html','http://www.baidu.com',
'http://34.54.65.3/dsdfjkk.htm','http://dhj.fdjjd.com/78078979/dsdfjkk.htm']
for one_url in ip_list:
ip_exist_one(one_url)
print ('****************************************************')
for one_url in ip_list:
ip_exist_two(one_url)
- 主要参考代码链接:https://www.jb51.net/article/141424.htm
https://www.cnblogs.com/ccz320/p/6536993.html
python 判断字符串是否为(或包含)IP地址的更多相关文章
- 在shell中如何判断字符串是否为有效的IP地址【转】
转自 在shell中如何判断字符串是否为有效的IP地址_echoisecho_新浪博客http://blog.sina.com.cn/s/blog_53a844e50100xxus.html 近来需要 ...
- python判断字符串中是否包含子字符串
python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1: print('存在') else: print('不存在' ...
- python判断字符串
python判断字符串 s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小 ...
- python判断字符串是否为空的方法s.strip()=='' if not s.strip():
python 判断字符串是否为空用什么方法? 复制代码 s=' ' if s.strip()=='': print 's is null' 或者 if not s.strip(): p ...
- python 判断字符串中是否只有中文字符
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...
- Python判断字符串编码以及编码的转换
转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...
- python判断字符串是否是json格式方法分享
python判断字符串是否是json格式方法分享 在实际工作中,有时候需要对判断字符串是否为合法的json格式 解决方法使用json.loads,这样更加符合'Pythonic'写法 代码示例: ...
- 用最基本的遍历来实现判断字符串 a 是否被包含在字符串 b 中,并返回第一次出现的位置(找不到返回 -1)
用最基本的遍历来实现判断字符串 a 是否被包含在字符串 b 中,并返回第一次出现的位置(找不到返回 -1) 例子: a='12';b='1234567'; // 返回 0 a='47';b='1234 ...
- 华为oj-判断输入的字符串是不是一个有效的IP地址
题目标题: 判断输入的字符串是不是一个有效的IP地址 详细描述: 请实现如下接口 boolisIPAddressValid(constchar* pszIPAddr) 输入:pszIPAddr 字符串 ...
随机推荐
- Java正则表达式应用
查找html中的图片 import java.util.regex.Matcher; import java.util.regex.Pattern; public class PicDownload ...
- 【原创】大叔问题定位分享(18)beeline连接spark thrift有时会卡住
spark 2.1.1 beeline连接spark thrift之后,执行use database有时会卡住,而use database 在server端对应的是 setCurrentDatabas ...
- Solr简单使用
1.添加索引 // 第一步:把solrJ的jar包添加到工程中. // 第二步:创建一个SolrServer,使用HttpSolrServer创建对象. SolrServer solrServer = ...
- mysql查看实时连接数
怎么实时查看mysql当前连接数 如何实时查看mysql当前连接数? 1.查看当前所有连接的详细资料:./mysqladmin -uadmin -p -h10.140.1.1 processlist ...
- Codeforces 1083C Max Mex [线段树]
洛谷 Codeforces 思路 很容易发现答案满足单调性,可以二分答案. 接下来询问就转换成判断前缀点集是否能组成一条链. 我最初的想法:找到点集的直径,判断直径是否覆盖了所有点,需要用到树套树,复 ...
- Python内置模块之subprocess
import subprocess ret = subprocess.Popen('netstat -ano',shell=True,stdout=subprocess.PIPE,stderr=sub ...
- [原创]创芯电子实验室iFPGA-Cable JTAG工具实物图
创芯电子实验室iFPGA-Cable JTAG工具实物图 对于Xilinx平台 基于FTDI 芯片的Xilinx JTAG 同时支持UART 电平1.8~5V 支持ISE和VIVADO 速度从10M. ...
- 记 Win10 + Ubuntu18.04 安装
目录 一.准备(一)环境(二)镜像(三)优盘 (四)启动项管理软件EasyBCD(五)启动优盘制作软件(六)分区二.安装 (一)优盘启动(二)安装windows10(三)安装ubuntu18.04(四 ...
- 通过ViewPager 实现图片轮播
通过ViewPager 实现图片轮播 首先来个效果图 布局文件: LinearLayout 用来存放下方的几个小白点. <?xml version="1.0" encodin ...
- Docker操作笔记(一)使用镜像
使用镜像 一)获取镜像 从Docker镜像仓库获取命令的格式是: docker pull [选项] [Docker Registry 地址[:端口号]] 仓库名[:标签] 具体的选项可以通过docke ...