I need to split the following string in one go in to an array. following is the string

"camera01_2012-04-13-10-14-12-625.jpg"

My code is String[] fileNameParts = fi.getName().split("[_-.]");

But it throws an exception saying "Exception: Syntax error U_REGEX_INVALID_RANGE near index 4:"

有帮助吗?

解决方案

- within character class is used for representing a range

To treat - literally in character class it can be at the beginning or end

With _-. you are representing a range of 95(decimal equivalent to ascii _) to 46(decimal equivalent to ascii .) which is invalid.

Use this regex

[-_.]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top