Created
January 27, 2018 15:39
-
-
Save seLain/30fc906706997fec64a1a54c0b00c893 to your computer and use it in GitHub Desktop.
prevent java.lang.String.split() from creating leading or trailing empty string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
example delimiters : [ !,?._'@] (including space) | |
*/ | |
String[] tokens = s.replaceFirst("^[ !,?._'@]+", "").split("[ !,?._'@]+"); | |
// to keep leading empty string | |
String[] tokens = s.split("[ !,?._'@]+"); | |
// to keep trailing empty string | |
String[] tokens = s.replaceFirst("^[ !,?._'@]+", "").split("[ !,?._'@]+", -1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment