Domanda

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

È stato utile?

Soluzione

- 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

[-_.]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top