I have an assignment to reverse engineer an SRPN calculator that takes String inputs through the command line. I'm trying to split that input into separate arrays for operators and operands, so the regex needs to be able to match the whitespace in "- 33", but not the boundary in "-33", for example.
I'm probably making this difficult for myself by using split, and thus having to match everything I don't want.
CodePudding user response:
You can try to remove whitespaces or any unnecessary chars with regex
^-.[0-9]
for - 2 it will be -2 or with trim() and replace().
Another soulution is to clear whole expresion leaving only numbers and defined operators with regex
[0-9() \-*/.]
CodePudding user response:
Please find the next WebSite is the most complete overview I ever saw regarding regex, I do not paste a code alike answer because depending on your string_value this could be accomplished with several different arrangements, Regex queries aren't a one answer topic, but instead wild beast that requires trial and error to find the right setup for your needs,
Reading this will take time, but it will teach you so much that you will be the Regex master of your company!
