Question

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:"

Was it helpful?

Solution

- 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

[-_.]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top