String[] ops = str.split("\\s*[a-zA-Z]+\\s*");
String[] notops = str.split("\\s*[^a-zA-Z]+\\s*");
String[] res = new String[ops.length+notops.length-1];
for(int i=0; i<res.length; i++) res[i] = i%2==0 ? notops[i/2] : ops[i/2+1];

This should do it. Everything nicely stored in res.

Answer from mmaag on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-split-string-using-regex
Java - Split String Using Regex - GeeksforGeeks
July 23, 2025 - Example 1: Here, we are using the most simple split() method with the regex \\d+, which splits the string wherever one or more digits appear. ... // Java program to split a string by digits public class SplitString{ public static void main(String[] args) { String s = "apple123banana456cherry"; // Split by one or more digits String[] p = s.split("\\d+"); for (String part : p) { System.out.println(part); } } }
🌐
Briebug
blog.briebug.com › home › articles › using the java string.split() method
Using the Java String.split() Method | Briebug
October 13, 2022 - It is a convenient method, provided by the Java String class to split a String into an Array of Strings, given the passed delimiter. There are two variants. One containing only the regex parameter and the other containing the regex and “limit”, ...
🌐
W3Schools
w3schools.com › java › ref_string_split.asp
Java String split() Method
The split() method splits a string into an array of substrings using a regular expression as the separator. If a limit is specified, the returned array will not be longer than the limit.
🌐
GeeksforGeeks
geeksforgeeks.org › java › split-string-java-examples
Java String split() Method - GeeksforGeeks
May 13, 2026 - The split() method in Java is used to divide a string into multiple parts based on a specified delimiter (regular expression). It returns an array of substrings after splitting the original string.
🌐
Reddit
reddit.com › r/learnprogramming › in java, how would i structure my regex to do a string split but only on commas, or commas followed by whitespace?
r/learnprogramming on Reddit: In Java, how would I structure my regex to do a string split but only on commas, or commas followed by whitespace?
November 24, 2021 -

**And round braces

Basically I have the following string split, but it breaks for multi word names. This is an example of the structure:

Sao Paulo, (-23.55, -46.63)

Where sArr is a string array, I attempted to match commas, whitespace and brackets, but didn't account for names with spaces.

sArr = line.split(("[\\s,(|)]+"));  

How could I match only commas, or commas with a whitespace, so that "Sao Paulo" doesn't turn into "Sao","Paulo"?

🌐
Reddit
reddit.com › r/java › still no split without regex?
r/java on Reddit: Still no split without regex?
February 23, 2016 -

Why does Java still not have a function in the standard lib which allows to split a string by using characters/strings without interpreting its argument as regex? I can't believe that - am I missing something?

EDIT: Just to make it clear, I don't have performance issues. It's more a general question, because I thought that splitting a string by a non-regex is often needed thus it should exist somewhere without using a lib like apache commons. Also, using Pattern.quote doesn't quite lead to the best readable code. I think I will stick to apache then. Thanks guys!

Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.regex.pattern.split
Pattern.Split Method (Java.Util.Regex) | Microsoft Learn
This method works as if by invoking the two-argument #split(java.lang.CharSequence, int) split method with the given input sequence and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The input "boo:and:foo", for example, yields the following results with these expressions: <table class="plain" style="margin-left:2em"> <caption style="display:none">Split examples showing regex and result</caption> <thead> <tr> <th scope="col">Regex</th> <th scope="col">Result</th> </tr> </thead> <tbody> <tr><th scope="row" style="text-weight:normal">:</th> <td>{ "boo", "and", "foo"}</td></tr> <tr><th scope="row" style="text-weight:normal">o</th> <td>{ "b", "", ":and:f"}</td></tr> </tbody> </table> Java documentation for java.util.regex.Pattern.split(java.lang.CharSequence).
🌐
Coderanch
coderanch.com › t › 684973 › java › Split-string-list-string-regex
Split the string and get a list of string using regex (Features new in Java 8 forum at Coderanch)
The group() method returns a String, one only, so, after using that, you are going to get a one‑element Stream downstream from there. If however you do what you say you are doing, namely split the String, you can get a String[]: look at the return value for this method. You will of course require a different regex.
🌐
Medium
medium.com › sina-ahmadi › java-regex-6e4d073aab85
Java RegEx. special characters issue in Java split… | by Sina | My journey as a software developer | Medium
June 20, 2018 - Replace all special characters using Java’s “replaceAll” method in the input string, with escaped special characters ... escapedString = nonEscapedString.replaceAll("\\*", "\\\\*"); splittedString = escapedString.split("\\*")
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › regex › Pattern.html
Pattern (Java Platform SE 8 )
April 21, 2026 - Pattern.matches(regex, input); behaves in exactly the same way as the expression ... If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time. ... Splits the given input sequence around matches of this pattern.
🌐
Oracle
forums.oracle.com › ords › apexds › post › split-string-using-regex-in-java-3911
split string using regex in java - Oracle Forums
February 14, 2008 - Hello, I've a flat file of data exported from a DB table. Columns are delimited with "|" (pipe) character. For e.g: there are 9 columns of data type varchar as: ID|TYPE|NAME|ADDRESS|ZIP|STA...
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
November 9, 2017 - The split() method is part of the String class in Java. Here’s its basic signature: String[] split(String regex) String[] split(String regex, int limit)
🌐
Baeldung
baeldung.com › home › java › java string › split a string in java and keep the delimiters
Split a String in Java and Keep the Delimiters | Baeldung
June 24, 2025 - First of all, let’s use the lookahead assertion “((?=@))” and split the string text around its matches: ... The lookahead regex splits the string by a forward match of the “@” symbol.
🌐
Coderanch
coderanch.com › t › 771194 › java › string-split-method-work
Why does my string.split(.) method not work? (Beginning Java forum at Coderanch)
programming forums Java Mobile ... The array answer is empty. ... The split() method takes a regular expression (regex) for an argument and a period happens to be a meta-character so you have to escape it with backslashes: "\\."...
🌐
Scaler
scaler.com › home › topics › split() string method in java with examples
split() String Method in Java with Examples - Scaler Topics
April 11, 2024 - We can simply say that the string is divided according to the provided regex. limit: the limit is an optional parameter. The limit is used to limit or control the number of strings generated.
🌐
Medium
medium.com › @AlexanderObregon › javas-string-split-method-explained-77bdaddaae79
Java’s String split() Method Explained
June 25, 2024 - The split() method in Java is defined in the String class and comes in two main forms: ... regex: This parameter represents the regular expression used to match the delimiter.
🌐
TutorialsPoint
tutorialspoint.com › how-to-split-string-in-java-using-regular-expression
How to split a regular expression in Java
August 21, 2024 - Following example demonstrates how to split a regular expression by using Pattern.compile() method and patternname.split() method of regex.Pattern class. import java.util.regex.Pattern; public class PatternSplitExample { public static void ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 09 › split-string-by-space-in-java
Split String by space in Java
However there is a difference between \\s+ and [ ] regex. \\s+ : It consumes all the consecutive spaces and doesn’t produce empty substrings. [ ] : It splits the string when the first space is encountered, which means if there are multiple consecutive spaces then it would produce empty strings.
🌐
LightNode
go.lightnode.com › tech › java-string-split
Mastering Java String Split: Essential Techniques for Efficient Text Processing
April 15, 2025 - While both can separate strings, split() offers more flexibility through regex patterns. StringTokenizer is slightly faster for simple delimiters but lacks the power of regular expressions. Additionally, StringTokenizer is considered somewhat outdated in modern Java development.