Basically, I have some strings like
5 - Avenue Rd
9 - Bellamy
21 - Brimley
191 - Highway 27 Rocket
And so on. I’m looking for a way using Google Guava to return the beginning digits. From what I’ve researched:
CharMatcher.DIGIT.retainFromis nice but I want it to stop at the first non-digit character.CharMatcher.DIGIT.trimLeadingFromis pretty much what I want, except that it returns the other part of the string where I want a string of digits instead.
Any ideas?
EDIT: added another example.
Expected output for the four examples above:
5
9
21
191
Not quite equivalent, but
Or — a bit more involved, but this will work with intermediate digits —
Or, with regexes, albeit with all the overhead that implies —