This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Pattern matching doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern matching doubt" Watch "Pattern matching doubt" New topic
Author

Pattern matching doubt

Sen George
Ranch Hand

Joined: Sep 21, 2005
Posts: 76
The following code


compiles and runs fine.

Program produces an output of 'match' found in positions 0, 1, 2, 3, 4, 5, 6, 7, and 8. But no data groups. How is this explained-matches found but no data groups?

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18541
    
  40

Program produces an output of 'match' found in positions 0, 1, 2, 3, 4, 5, 6, 7, and 8. But no data groups. How is this explained-matches found but no data groups?


Well, look at the pattern....




This reluctantly matches zero or more digits. Since, zero digits is a valid match, an zero length string is a valid match -- which is what you are matching.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pattern matching doubt
 
Similar Threads
can some one explain me the output of this program?
pattern matcher
greedy quantifier; find() method
Regex - Matcher class
doubt on group() in Matcher class