I'm having a hard time using regular expressions in Java even after reading numerous tutorials online. I'm trying to extract parts of a String received to be used later in my application.
Here are examples of the possible String received:
53248 <CERCLE> 321 211 55 </CERCLE>
57346 <RECTANGLE> 272 99 289 186 </RECTANGLE>
The first number is to be extracted as a sequence number. The word between <> is to be extracted as well. Then, the sequence of numbers in between as well.
Here is my pattern:
"(\\d+)\\s*<(\\w+)>\\s*((\\d+\\s*)+)\\s*</\\w*>.*"
Here is the code for my method so far:
public decompose(String s) throws IllegalArgumentException {
Pattern pattern = Pattern.compile(PATTERN);
Matcher matcher = pattern.matcher(s);
noSeq = Integer.parseInt(matcher.group(1));
type = typesFormes.valueOf(matcher.group(2));
strCoords = matcher.group(3).split(" ");
}
Problem is that when I run the code, all my matcher groups are at -1 for some reason (not found I guess). I've been banging my head on this for a while and any suggestion is welcome :) Thanks.