有效载荷:
2016-07-18 16:51:47 GMT 10.65.242.97 WinNT://CSLG1\mbr04105 CONNECT https stats.g.doubleclick.net 443 / - 1925 5148 0 173.194.206.156 c:infr default allow 12.3.33.9
当前正则表达式解析IP(它现在抓取第一个IP)
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
答案 0 :(得分:-1)
为了获取一个表达式中的第一个和第二个地址,锚定到文本行开始并放置由非贪婪填充符分隔的两个IP地址模式:
^.*?((?:\d{1,3}\.){3}\d{1,3}).*?((?:\d{1,3}\.){3}\d{1,3})
答案 1 :(得分:-1)
使用Class Patter AND Matcher。
代码:
String yourString = ...
Pattern regular = Pattern.compile("your regex");
Matcher match = regular.matcher(yourString);
match.find()//to make the match
String firstIP = yourString.substring(match.start(),match.end());
String newString = yourString.substring(match.end(),yourString.length());
regular = Pattern.compile("your new regex for the second IP");
//if it is the same regex you can skip this.
match = regular.matcher(newString);
match.find()
String secondIP = newString.substring(match.start(),match.end());