java - Split a string by period, but string contains float numbers -
i have string formed names (w/o spaces) separated periods. each token (after period) can start [a-za-z_]
or [
(and ends ]
) or $
(and ends $
).
examples:
- house.car.[0].flower
- house.car.$something$
- house.car2.$4.45$.[0]
- house.car2.$abc.def$.[0]
so need split string period, in last 2 examples dont want split 4.45
(or abc.def
). surrounded $
should not splitted.
for last 2 example want array that:
- house
- car2
- $4.45$ //fixed, sabuj hassan
- [0]
or
- house
- car2
- $abc.def$
- [0]
i have tried use regex, i'm wrong.
i informed after closing $
there could string surrounded <
, >
can again contain dots should not split:
house.car.$abc.def$<ghi.jk>.[0].bla
and need like:
house
car
$abc.def$<ghi.jk>
[0]
bla
thanks help.
you better off collecting results "walking" string match .find()
:
// note alternation private static final pattern pattern = pattern.compile("\\$[^.$]+(\\.[^.$]+)*\\$|[^.]+"); // public list<string> matchesforinput(final string input) { final matcher m = pattern.matcher(input); final list<string> matches = new arraylist<>(); while (m.find()) matches.add(m.group()); return matches; }
Comments
Post a Comment