This is specifically aimed at parsing hex bytes, but there's a more general question here.
Suppose I have a regexp r
e.g. \\s*([0-9A-Fa-f]{2})\\s*
(optional spaces, 2 hex digits that I'm interested in, and optional spaces).
If I want to parse a string s
with this regexp such that:
if
s
can be divided into a sequence of blocks that matchesr
, I want to do something for each block. (e.g.ff 7c 0903 02BB aC
could be divided in this way.)If
s
cannot be divided accordingly, I want to detect this. (e.g.00 01 02 hi there ab ff
and9 0 2 1 0
andY0 DEADBEEF
andcafe BABE!
all fail.)
how could I do this with Java's regexp facilities?