How to write the regular expression for below kind of String such that I get response in below format ?
"abc, -xyz, lmn, qwe,-yui"
Basically I need to parse above string in List<String>
as
abc, -xyz
lmn
qwe, -yui
Below code is working fine when there is exactly one space before hyphen(-) ex:
"abc, -xyz"
but not working when there is no or more than one space, ex:
"abc, -xyz"
Regular expression I tried:
List<String> items = Arrays.stream(order.split("(?!, -),")).map(String::trim).map(String::toLowerCase).collect(Collectors.toList());
Please provide the code which parse with any number of spaces and also explain the logic for the same.