Friday, 9 August 2013

Extract only the numbers from String

Extract only the numbers from String

I need a Regex that given the following Strings: "12.123.123/1234-11",
"12.123123123411" or "1123123/1234-11". I could extract only the
numbers(12123123123411);
Pattern padrao = Pattern.compile("\d+");
Matcher matcher = padrao.matcher("12.123.123/1234-11");
while (matcher.find()) {
System.out.println(matcher.group());
}
//output:12,123,123,1234,11,
//I need: 121231234123411
Can anyone help me?

No comments:

Post a Comment