Bookmark Topic Watch Topic
  • New Topic

Doubt regarding Regex "?" quantifier

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi

I tried out the following code :



The output is:

0 0
1 2 a
2 2
3 4 a
4 4

a) Why is matcher.start() and matcher.end() returning 4 4 as output? The source string itself has only 3 zero-based index positions("baba").

b) Secondly, when an instance of "a" is found , matcher.end() returns the next index position. Like when it finds "a" at index position 1, it returns 2 for matcher.end(). Why so?
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate of http://www.coderanch.com/t/604628/java-programmer-SCJP/certification/Regex-quantifier
 
    Bookmark Topic Watch Topic
  • New Topic