File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Groups Usage (Pattern & Matcher ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Groups Usage (Pattern & Matcher )" Watch "Groups Usage (Pattern & Matcher )" New topic

Groups Usage (Pattern & Matcher )

Krishna Mir

Joined: Jan 09, 2006
Posts: 12
When regular expressions are used as patterns to match the input strings, it results in groups of strings that have matched the pattern. These groups can be accessed using a back reference \n where n is the index of the group captured. I didn't understand the following table.

Whole content Regular expression Result

abab ([a-z][a-z])\1 Found the text "abab" starting at
index 0 and ending at index 4.

abcd ([a-z][a-z])\1 No match found

abcd ([a-z][a-z]) Found the text "ab" starting at
index 0 and ending at index 2.
and the text "cd" starting at
index 2 and ending at index 4

Can anybody please help me to undetstand above?

I agree. Here's the link:
subject: Groups Usage (Pattern & Matcher )
It's not a secret anymore!