I have a string like this
length 10 cm width 2 cm depth 0.5 cm / length 10 cm width 2 depth 0.5 cm
I want to get output like
length 10 cm
width 2 cm / width 2
depth 0.5 cm
I tried this
public static void main(String []args) {
String s = "length 10 cm width 2 cm depth 0.5 cm";
String[] tok = s.split("(?<=\\d)\\s");
for(int i=0; i< tok.length; i++) {
System.out.println(tok[i]);
}
}
It returns:
length 10
cm width 2
cm depth 0.5
cm
Try the following match pattern.
(?: (?<![/*+-] )(?=length|width|depth))
Output
length 10 cm
width 2 cm
depth 0.5 cm / length 10 cm
width 2
depth 0.5 cm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With