Java Utililty Methods String Split by Regex

List of utility methods to do String Split by Regex

Description

The list of methods to do String Split by Regex are organized into topic(s).

Method

Collectionsplit(final String regex, final String value)
split
return split(regex, value, new LinkedList<String>());
Listsplit(final String string, final String regex)
split
String tokens[] = string.split(regex);
return Arrays.asList(tokens);
String[]split(String input, String regex)
Splits the input string with the given regex and filters empty strings.
if (input == null) {
    return null;
String[] arr = input.split(regex);
List<String> results = new ArrayList<>(arr.length);
for (String a : arr) {
    if (!a.trim().isEmpty()) {
        results.add(a);
...
Listsplit(String str, String regex)
split
List<String> strList = null;
if (str == null || str.equals("")) {
    return strList;
strList = Arrays.asList(str.split(regex));
return strList;
Listsplit(String str, String regex)
Splits the given string using the given regex as delimiters.
return (Arrays.asList(str.split(regex)));
String[]split(String string, String pattern)
Split a string on pattern, making sure that we do not split on quoted sections.
assert string != null;
assert pattern != null;
List<String> list = new ArrayList<String>(1);
StringBuilder builder = new StringBuilder();
boolean inQuotes = false;
for (int i = 0; i < string.length(); i++) {
    if (!inQuotes && match(pattern, string, i)) {
        list.add(builder.toString());
...
String[]split(String text, String pattern)
Splits a string given a pattern (regex), considering escapes.
String[] array = text.split(pattern, -1);
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < array.length; i++) {
    boolean escaped = false;
    if (i > 0 && array[i - 1].endsWith("\\")) {
        int depth = 1;
        while (depth < array[i - 1].length()
                && array[i - 1].charAt(array[i - 1].length() - 1 - depth) == '\\')
...
ListsplitAndTrim(String s, String regex)
split And Trim
if (s == null) {
    return null;
List<String> returnList = new ArrayList<>();
for (String string : s.split(regex)) {
    returnList.add(string.trim());
return returnList;
...
ListsplitList(String list, String splitRegex)
split List
String[] parts = list.split(splitRegex);
List<String> finalParts = new ArrayList<String>();
for (String part : parts) {
    if (!part.equals("")) {
        finalParts.add(part);
return finalParts;
...
ArrayListsplitNoEmpty(String sStr, String regex)
split No Empty
String[] aIn = sStr.split(regex);
ArrayList<String> lRes = new ArrayList<String>();
if (aIn.length == 0) {
    lRes.add("");
    return lRes;
for (int i = 0; i < aIn.length; i++) {
    if (!aIn[i].isEmpty() && !aIn[i].matches("\\s+") && aIn[i].length() > 1) {
...