• 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

hexadecimal regex

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Let's say that we want to create a regex pattern to search for hexadecimal literals. As
a first step, let's solve the problem for one-digit hexadecimal numbers:
0[xX][0-9a-fA-F]"




This is from Kathy Sierra and Bates SCJP book page 492 regarding regex. I don't quite understand why the index goes from 0 to 9, then from 0 to 7 rather than from 0 to 18. And the explanation says that the regex returns position 6 and 11, but I don't see any 11. What am I missing?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Array indices in Java start at zero. So if I have

then x.length is 3, and x has indices 0..2, where x[0] is 2, x[1] is 4, and x[2] is 6.

The index line you show is just a shorthand to show you where you are in the given group of 10.


They just didn't show the top line indicating the tens value.

And it should have lined up like:

 
Vonique Leary
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that is simple enough. Thanks so much for the explanation!

Vonique
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic