| Author |
groupcount() method in MatchResult Interface in Java 5
|
Sarada Bikkina
Greenhorn
Joined: Jan 30, 2006
Posts: 9
|
|
Hi Frnds, I was actually going through a program using scanner where i found the MatchResult Interface.Here is the block of code which i went through String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input); s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); MatchResult result = s.match(); for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i); s.close(); and the ouptut is : 1 2 red blue i didnt understand the funtionality of the groupCount() and the group() methods.can anyone please explain me? Thanks in Advance
|
Thanks N Regards,<br /> Sarada Bikkina
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
i didnt understand the funtionality of the groupCount() and the group() methods.can anyone please explain me?
Unfortunately, there is no simple explanation -- if you don't know what Regular Expressions are. The match() method returns the last Regex match object used. The group and group count are related to Regex groups. In this example, the groups are the parts of the match between the "(" and ")", of the regex pattern used by the findInLine() method. For more information, you will need to google some tutorials on Regex. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: groupcount() method in MatchResult Interface in Java 5
|
|
|