Hi, I'm trying to find a good way to get a Scanner to use a given delimiter as a token. For example, I'd like to split up a piece of text into digit and non-digit chunks, so ideally I'd just set the delimiter to \D
and set some flag like useDelimiterAsToken, but after briefly looking through the API I'm not coming up with anything. Right now I've had to resort to using combined lookaheads/lookbehinds for the delimiter, which is somewhat painful:
scanner.useDelimiter("((?<=\\d)(?=\\D)|(?<=\\D)(?=\\d))");
This looks for any transition from a digit to a non-digit or vice-versa. Is there a more sane way to do this?