简体   繁体   中英

Regex Invalid Escape Sequence on Split String

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.

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}&&[^-]]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM