java - TCPdump parsing sequence number using regular expressions -
i creating program read packet tcpdump, , read sequence number. using regular expressions, code isn't working.
public long getsequencenumber(string packet){ pattern p = pattern.compile("seq.\\d*"); matcher m = p.matcher(packet); if(m.matches()){ pattern num = pattern.compile("\\d*"); return long.getlong(num.matcher(m.group()).group()); } return -1; }
the following prints -1:
system.out.print(getsequencenumber("blahbdds seq 1910428391283 ldskgj"));
any suggestions? thanks!
what need matcher.find()
, long.valueof()
:
public class main { public static void main(string[] args) { system.out.println(getsequencenumber("bladds seq 1910428391283 ldskgj")); } public static long getsequencenumber(string packet){ pattern p = pattern.compile("seq.(\\d*)"); matcher m = p.matcher(packet); if(m.find()){ return long.valueof(m.group(1)); } return -1; } }
output:
1910428391283
see demo here.
Comments
Post a Comment