java - Is this the most efficient way to parse the string? -
i have string of form au 12345t
or au 12345t1
; of form alphabet characters(s) followed number ending in 1 or 2 character alpha-numeric string.
i using following regular expression me result:
^[a-z|a-z]+|[0-9]+|[a-z|a-z][0-9]?
would efficient way parse such string?
so example au 12345t
, want result separated 3 tokens: au
, 12345
, t
; au 12345t1
should au
, 12345
, t1
(since ending characters can alpha-numeric , max length 2)
this should it:
[a-za-z]+\s?[0-9]+[a-za-z0-9]{1,2}?
if want separate strings said, put parenthesis around blocks, so:
([a-za-z]+)\s?([0-9]+)([a-za-z0-9]{1,2}?)
this have regex return each group individually.
all being said, you'll want ensure final one/two character alphanumeric string begins letter, or else you'll have no way of separating second token third token.
Comments
Post a Comment