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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -