aspose file tools*
The moose likes Beginning Java and the fly likes Why is start_index of java.util.regex.Matcher more than input-string's length? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is start_index of java.util.regex.Matcher more than input-string Watch "Why is start_index of java.util.regex.Matcher more than input-string New topic
Author

Why is start_index of java.util.regex.Matcher more than input-string's length?

Leon Omk
Ranch Hand

Joined: Aug 17, 2010
Posts: 75


Result:
0 [] 0
1 [] 1
2 [3] 3
3 [4] 4
4 [] 4
5 [] 5 //I'm uncomfortable with this one, since max index for "ab34e" is 4.

Why can't Matcher smart enough to stop at index 4 ? help!


OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19063
    
  40


Question from FAQ, that is similar to this one:

http://www.coderanch.com/how-to/java/SCJP-FAQ#kb-regexp


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Leon Omk
Ranch Hand

Joined: Aug 17, 2010
Posts: 75

Thanks Henry.



Result:
0 [ab34e] 5
5 [] 5

In other words, "nothing" is a match for *, and this "nothing" is at the index 5.

Although index 5 doesn't exist in "ab34e", but somehow it exists inside the Matcher.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is start_index of java.util.regex.Matcher more than input-string's length?