Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Leon Omk
Ranch Hand
Posts: 75
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!

 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question from FAQ, that is similar to this one:

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


Henry
 
Leon Omk
Ranch Hand
Posts: 75
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic