I want my delimitation regex to contain these conditions. Is it possible?

I have a Java calculator. It’s a talkative calculator, I designed it react as human-like as I could to all kinds of input, even “garbage” input. For example, if you typed in 5# * I$, it would say something like, “Oh, your first number starts as an integer, but then it gets unclear. I can’t figure out your second number too. It starts with a Latin letter, but it doesn’t seem a Roman numeral”. Then I decided to include a smart delimitation procedure. My goal was to make it possible for my calculator to process expressions like 5+3 (as opposed to 5 + 3). At the point of this writing, my useDelimiter() method’s parameter is


It works, but has issues (for example, 1, 2). One of those is it somewhat robs a user of those natural-ish reactions to nonstandard tokens. For instance, if you input the same line, 5# * I$, scanner would delimit it into 5, #, and * so it would see no issue with the first number and wouldn’t comment on it (though, it would remark that * is not a real number). To fix this, I think, I need to find a way to turn into a regex the following expression: if input contains +, -, *, or / (allowed operations) – except when it begins with + or - – separate the first character of that type from anything that adjoins it on the left and anything that adjoins it on the right to the next operation character or the end of input (and throw out spaces, if any). Else, apply the delimitation pattern that I pasted above. If I could translate all that into a regex, I would see these results

123&$45 → 123, &$, 45
123&$IV → 123, &$, IV
123+45 → 123, +, 45
123+$45 → 123, +, $45 (not 123, +$, 45)
123$+45 → 123$, +, 45 (not 123, $+, 45)
123$+4&5 → 123$, +, 4&5 (not 123, $+, 4)
123$+4-5 → 123$, +, 4 (not 123, $+, 4, but also not not 123, $+, 4-5)
-123-45 → -123, -, 45 (not -, 123, -, 45)

Can I do that? Is it possible?

UPD: I tried to to it on my own, here’s my new regex


The problem? “Repetition not allowed inside lookbehind”

What it means in practice is that, first, I can’t run a program before I remove that first plus, and second, once I remove it, the scanner will delimit input like 123$+45 into 123, $, +, and 45 as opposed to 123$, +, and 45

So to recap, in case it’s confusing. I need to take my new useDelimiter() and

  1. Convince Java to accept plus in the first lookbehind – or something to that effect
  2. Add exception to this section (?<=[-+*/])(?=.+): except when it begins with + or -
  3. (considering my previous question) Add exception to this section (?<=[\\dA-z.,])(?=[^\\dA-z.,]): except when it ends with [^\\dA-z.,] (that is, any character except for digits, letters, a dot, and a comma)
  4. (considering my another previous question) Convince Java to interpret ^ in my regex only as an “except for” operator, not the ^ character – or something to that effect