1

I like to split a string into an array by using the split(regex) function.

I want to split it on semicolons ; - but there are also "escaped" semicolons in the String (\;) which should not be used for the split.

Is there a regex for the .split(regex) function that would do this?

1 Answer 1

6

Use negative look-behind to split on semi-colon not preceded by \\: -

str.split("(?<!\\\\);");

You need to use 4 backslashes - escape a backslash once for Java, and then escape the 2 backslashes again for regex.

Sign up to request clarification or add additional context in comments.

Comments

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.