How to use Guavas delimiter and keep delimiters (without regex)?

Is there an easy way to use Splash Guavas to split a string and save separators without using regular expressions?

Sort of

String string = "1+2-3*40";
Splitter splitter = Splitter.on(CharMatcher.DIGIT.negate()).retainDelimiters();

This gives

[1, +, 2, -, 3, *, 40]

I know about Splitter.onpattern (), but it will require a regular expression from me (however, I am trying to avoid this).

+5
source share
1 answer

I don’t think it can be done in Guava, but you can send a function request . By the way, what will be the way out for "1+3**2"? I think it will be unequivocal here.

+1
source

All Articles