• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How work end() method from class Matcher?

 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


result:
0 0
1 2 a
2 2
3 3
4 5 a
5 5
Can anyone explain how matcher.end() work, what it find?
from
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#end%28%29
Returns the offset after the last character matched.
but i shill not understand
0 0 - there is no matched, but there is zero matched
1 2 a - there second char from start, definitely there is matched
2 2 - there is no matched, but there is zero matched, last matched was a and use previous matched offset
3 3 - but here again there is no matched, but there is zero matched why result is 3 not 2
4 5 a
5 5
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a? matches either zero characters or a single 'a' character. Since each character is either a or not a (zero characters), every index will match.

0 0 prints on the match of zero characters. Note this is different than "no match". There is a match. It is of length zero which means the start and end indexes will be the same. This logic applies to 3 3 as well. The
 
reply
    Bookmark Topic Watch Topic
  • New Topic