Using example code on SO I found, and a string I'm searching, I'm trying to capture groups of aircraft classes and their seats. The input file has the aircraft configuration in the form J28W36Y156 which means 28 J (business) class seats, 36 W (premium economy seats) and 156 Y (economy) seats.
The Java code I'm using is as follows:
s = "J12W28Y156";
patternStr = "(\\w\\d+)+";
p = Pattern.compile(patternStr);
m = p.matcher(s);
if (m.find()) {
int count = m.groupCount();
System.out.println("group count is "+count);
for(int i=1;i<=count;i++){
System.out.println(m.group(i));
}
}
The regex seems to only capture the LAST class seat config ie. Y156. How do I get this regex to capture all of the class/seat combos in multiple groups. Does this have something to do with it being a 'greedy' match I need to specifiy? I would like the output to be something like an array eg.
{J12, W28, Y156}
Thanks guys.