V
valan.wood
In http://www.javaregex.com/RegexRecipesV1.pdf, I found a nifty little
example which illustrates what I'm trying to do:
Pattern p = Pattern.compile("(?i)((apple|orange|banana)[\\s,]*)+");
String txt = "List some fruits: apple, orange, banana";
Matcher m = p.matcher(txt);
boolean found = m.find();
System.out.println(m.group());
// Prints "apple, orange, banana"
System.out.println(m.group(1));
// Prints "banana"
System.out.println(m.group(2));
// Prints "banana"
Notice how it grabs "banana", but not "apple" or "orange". I'm
thinking it should match all three, for a total of 6 groups. Is there
a way to match all six without introducing a while (m.find()) loop?
example which illustrates what I'm trying to do:
Pattern p = Pattern.compile("(?i)((apple|orange|banana)[\\s,]*)+");
String txt = "List some fruits: apple, orange, banana";
Matcher m = p.matcher(txt);
boolean found = m.find();
System.out.println(m.group());
// Prints "apple, orange, banana"
System.out.println(m.group(1));
// Prints "banana"
System.out.println(m.group(2));
// Prints "banana"
Notice how it grabs "banana", but not "apple" or "orange". I'm
thinking it should match all three, for a total of 6 groups. Is there
a way to match all six without introducing a while (m.find()) loop?