I want to strip out anything from a string that isn't a plus sign, or a minus, or a multiplication sign or a division sign (/).
So i thought I'd use RegEx and negative lookahead.
Given a Java array:
String[] operandsArray = str.split("(?!\\u002A|\\u002B|\\u002D|\\u002F).")
And a test string of 55+5, the resulting array operandsArray contains:
0:""
1:""
2:"+"
I'm looking for it to contain just the operands, so:
0:"+"
and given: 55+6-6*6/6, would return:
0:"+"
1:"-"
2:"*"
3:"/"
It should also match duplicates as well, so given 5+5+5+5, would return:
0:"+"
1:"+"
2:"+"
Can anyone help with this, thanks
[-+/*]regex.[-+/*]will strip out the operands and leave behind anything else, resulting in an array that, say given 55+5, would contain 55 and 5, I'm looking to do the opposite so that only * would remainstr.replaceAll("[^-+/*]","").split("")split, useMatcher#findas I showed in my top comment.