0

I'm attempting to make my String array split on whitespace or any punctuation besides the dash character. This is my attempt:

String[] temp = lowerCased.split("\p{Blank}\\\p{Punct}&&[^-]]");

I'm getting the Invalid Escape Sequence and I figure it has to do with Java's need for a double backslash, but I can't pinpoint where exactly it's going wrong. I put it into one of the Regex emulation programs and it seemed to get the result I was going for.

1
  • 2
    The first backslash is not escaped, it should be. There are three backslashes in the middle when two backslashes will do. Also you have a hanging ]. Commented May 1, 2015 at 6:59

1 Answer 1

1

The backslashes are not escaped properly, try this. There is also a left square bracket missing at the beginning.

String[] temp = "".split("[\\p{Blank}\\\\p{Punct}&&[^-]]");
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.