I have the following piece of code:
String range = "(15-42)";
String regexp = "(\\d{1,})(\\d{1,})";
Pattern p = Pattern.compile(regexp);
Matcher m = p.matcher(range);
m.find();
System.out.println(m.groupCount());
for(int i=0; i<=m.groupCount(); i++){
System.out.println("value:" + m.group());
}
And then I have the following output:
2
value: 15
value: 1
value: 5
But I'm only expecting to see 2 values: 15 and 42.
Why doesn't this work as expected?
String regexp = "(\\d{1,})-(\\d{1,})";. See ideone.com/JeNO2u