extracting contents from a string using regex
Hi,
is there a way to extract 1521411 etc. numbers from the following string
to some seperate string variables using util.regex, so then i can parse them to integers later?
note: the following is the "string" with whitespaces and \r\n
## vcc1 (down)vpivcitypeencap
0100DATA_PVCPPP-VC
pktoctdiserr
stat-tx-payload 152141115154 0 0
stat-rx-payload 251647524784 0 0
Thanks in advance!
[443 byte] By [
csea] at [2007-9-27 16:07:35]

Not quite sure if you are expecting two numbers or four from the above. The code below gives you two.
String s = "## vcc1 (down) vpi vci type encap\r\n"
+"0 100 DATA_PVC PPP-VC\r\n"
+"pkt oct dis err\r\n"
+"stat-tx-payload 1521411 15154 0 0\r\n"
+"stat-rx-payload 2516475 24784 0 0";
java.util.regex.Pattern p = java.util.regex.Pattern.compile("\\d{6}");
java.util.regex.Matcher m = p.matcher(s);
while (m.find())
System.out.println("found=" + m.group());
Thanks for your reply!
I forgot to mention that the numbers in the string are not known, as you
can see, the string is the feedback from a router's stats, so we cant tell
how many digits it will have next time we send the same query.
I tried several ways to capture the word (stat-tx-payload and stat-rx-payload)
in front of those numbers, but some how it does work if the string contains
\r\n ... ...
csea at 2007-7-6 0:26:18 >
