-1

Have the next regex /+|-^[(-], which I use in String.split(regex) method.

I want to split in situations when there is plus or minus, but if it's minus then don't split if before him there is opening parentheses.

Correct example: toDollar(-45euro)-$30 ----> { toDollar(-45euro) , $30 }.

So my regex doesn't follow this rule, how to modify it ?

1

1 Answer 1

2

You are looking for is a negative lookbehind:

\\+|(?<!\\()-

(?<!...) is the lookbehind and means "not preceded by ..."

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.