fyqt.net
当前位置:首页 >> 用jAvA 正则表达式 提取IP地址 >>

用jAvA 正则表达式 提取IP地址

用正则表达式提取网址的方式如下: 用ifconfig来提取 ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'192.168.10.1 用ip addr来提龋 ip addr | grep -Po '[^ ]+(?=/\d)'

ip的正则表达式网上很多,比如:((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?) 找文本中匹配的字符串好像Scanner有几个find***方法,但是我看不懂文档中对他们的解释 过滤重复可以使用set来存储这些ip,一样的就不会被重...

IP地址:(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d) 邮件地址:[a-zA-Z0-9._%+-]+@(?!.*\.\..*)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}

package com;public class Joey{public static void main(String[] args){String ip = "10.1.107.0/24";String reg = "^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)/\\d+$";System.out.println(ip.matches(reg));}}

正则表达式匹配ip地址,实际上就是分别判断每个点直接的数字是否符合规范。 package com; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestRegex { public static boolean isboolIP(String ipAddress){ Stri...

String reg = ".*\\/\\/([^\\/\\:]*).*";String str1 = "http://192.168.1.6:9999/caservice/webservice/caServiceWs?wsdl ";System.out.println (str1.replaceAll (reg, "$1"));String str2 = "http://192.168.1.6/caservice/webservice/caServ...

String regex="//(.*?):(.*)"; Pattern p=Pattern.compile(regex); String t="://127.0.0.1:8080"; Matcher m=p.matcher(t); while(m.find()){ System.out.println(m.group(1)); System.out.println(m.group(2)); }

你直接用matchs判断就可以了,matcher是只要内部有能匹配上的就算满足,不是判断整体。 String rexp = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";String addr = "11111.1.1.1";System.out...

string str = @"190.73.128.12808019.73.128.12080190.73.80.1208080190.73.12.12015559192.168.128.1208080"; str = Regex.Replace(str, @"", ":"); MatchCollection mc = Regex.Matches(str,@"\d{2,3}([.]\d{1,3}){3}:\d{2,5}"); foreach (Ma...

// 回答完毕,采纳即可import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Drinks{public static final String LINE = System.g...

网站首页 | 网站地图
All rights reserved Powered by www.fyqt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com