File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes hexadecimal regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hexadecimal regex" Watch "hexadecimal regex" New topic

hexadecimal regex

Vonique Leary
Ranch Hand

Joined: Mar 24, 2008
Posts: 107
"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:

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?
Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

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

Joined: Mar 24, 2008
Posts: 107
Well, that is simple enough. Thanks so much for the explanation!

I agree. Here's the link:
subject: hexadecimal regex
It's not a secret anymore!