How to split String without regex

String::split do split without regex if the regex is:

  • a one-char String and this character is not one of the RegEx's meta characters .$|()[{^?*+\\
  • two-char String and the first char is the backslash and the second is not the ascii digit or ascii letter.

Please see String::split() source code for details.

For escaped '.' target it is going to be split without regex.


You need to escape your "target" in order to use it as a regex. Try

String[] someStringSplit = someString.split(Pattern.quote(target));

and let me know if that helps.