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 - ... // 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) { ...
Discussions

In Java, how would I structure my regex to do a string split but only on commas, or commas followed by whitespace?
Use an optional: ",\s?" This means: "a comma, followed by 0 or 1 whitespace char". If you must allow for more than 1 whitespace, use ",\s*". The "*" means "0 or more". A good regex reference I know is: https://www.regular-expressions.info/ More on reddit.com
🌐 r/learnprogramming
15
4
November 24, 2021
S4248 Regex patterns should not be created needlessly - false positive
SonarQube 6.7.6 SonarJava 5.11 RSPEC-4248 String’s split method has an optimization that doesn’t create a regex if the parameter is a one character string. RegexPatternsNeedlesslyCheck tries to detect this case, but fails for “\n”. The following code triggers S4248, when it shouldn’t. ... More on community.sonarsource.com
🌐 community.sonarsource.com
1
0
April 8, 2019
Need help splitting string with regex
It is true the problem is in escaping as u/AnnoMMLXXVII suggests, however not in +, but -. since that's the only symbol that actually means something in this context. The actual regex should therefore be: (?<=[+\\-/*]) More on reddit.com
🌐 r/learnjava
7
0
August 10, 2023
Split String every nth char / or the first occurrence of a period
If you want to split only on full sentences, just check for the location of the next full stop. If the phrase length is less than 15 characters, search for the subsequent full stop, check the length of both is still less than 15, and add it to the phrase. Repeat until the phrase is longer than 15 characters. More on reddit.com
🌐 r/java
8
0
August 28, 2013
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
July 15, 2026 - 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)
🌐
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.
🌐
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"?

🌐
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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.regex.pattern.split
Pattern.Split Method (Java.Util.Regex) | Microsoft Learn
Splits the given input sequence around matches of this pattern. [Android.Runtime.Register("split", "(Ljava/lang/CharSequence;I)[Ljava/lang/String;", "")] public string[] Split(Java.Lang.ICharSequence input, int limit);
Find elsewhere
🌐
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.
🌐
IONOS UK
ionos.co.uk › digital guide › websites › web development › string splitting in java
How to split strings in Java - IONOS UK
January 6, 2025 - You can also use split() in Java with strings con­tain­ing lists separated by commas. You’ll just need to use a little trick, because of how precisely your in­struc­tions are im­ple­men­ted in Java. First, let’s look at an example without the trick. Say we have a list of the days of the week, separated by commas. These commas make for the perfect separator to enter into regex.
🌐
Sonar Community
community.sonarsource.com › rules and languages › report false-positive / false-negative...
S4248 Regex patterns should not be created needlessly - false positive - Report False-positive / False-negative... - Sonar Community
April 8, 2019 - SonarQube 6.7.6 SonarJava 5.11 RSPEC-4248 String’s split method has an optimization that doesn’t create a regex if the parameter is a one character string. RegexPatternsNeedlesslyCheck tries to detect this case, but fails for “\n”. The following code triggers S4248, when it shouldn’t. String str = "abc"; str.split("\n");
🌐
IONOS UK
ionos.co.uk › digital guide › websites › web development › java strings
How to use Java strings - IONOS UK
January 6, 2025 - With the Java split() method you can divide a Java string into smaller sub­strings. Here is its syntax: String[] split(String regex)java ·
🌐
Salientsoft
salientsoft.co.uk
Salient Soft » Regex
String.split is now the preferred means of tokenising strings as java.util.StringTokeniser is now deprecated. String.split returns a string array containing the split strings. Using String.split requires some understanding of regular expressions, so I have included a couple of simple examples here. ... This example takes string input and splits it on any white space (including newlines) or commas. Multiple white space and/or multiple comma characters are treated as a single delimiter. The regex string operates as follows:-
🌐
Greenfoot
greenfoot.org › topics › 54158 › 0
Greenfoot | Discuss | Splitting up strings?
Do not worry about 'regex' for now (that is just a limiting value for the number of "words" to be extracted from the sentence). Use the more simple 'split(String)' method. The String parameter is the separator String -- a simple space ( " " ) should do for it.
🌐
Reddit
reddit.com › r/learnjava › need help splitting string with regex
r/learnjava on Reddit: Need help splitting string with regex
August 10, 2023 -

I'm trying to split a list of strings while keeping the delimiters ("+", "-" , "*" , "/") but I keep running into this problem where a string will also split at decimals as well. Given the input [-14.0x, -12.0] it will return [-, 14., 0x, -, 12., 0] but the expected result is [-, 14.0x, -, 12.0]. Any help is greatly appreciated.

private List<String> splitTerms(List<String> terms) {
    List<String> splitTerms = new ArrayList<>();

    for (String term : terms) {
        String[] operatorAndTerms = term.split("(?<=[+-/*])");

        for (String split : operatorAndTerms) {
            splitTerms.add(split);
        }
    }
    return splitTerms;
}

🌐
InformIT
informit.com › articles › article.aspx
9.4. Regular Expressions | Processing Input and Output | InformIT
With a limit of zero, trailing empty strings are discarded. If you don’t care about precompiling the pattern or lazy fetching, you can just use the split and splitWithDelimiter methods of the String class:
🌐
JRebel
jrebel.com › blog › java-regular-expressions-cheat-sheet
Java Regular Expressions (Regex) Cheat Sheet | JRebel
July 30, 2025 - Our Java regex cheat sheet offers the correct syntax for Regex Java, including classes and methods, boundary matchers, quantifiers, and more.
🌐
University of Edinburgh
geos.ed.ac.uk › ~bmg › software › Perl Books › RegExp_perl_python_java_etc.pdf pdf
Regular Expression Pocket Reference, Second Edition
Java (java.util.regex) | 29 · tern and capture submatch into \1,\2,... ... matched by the nth capture group. ent string, contains text matched by the · roup. ttern, but does not capture submatch. ping. ns in alternation. ore times. ore times. times. y n times.
🌐
Built In
builtin.com › software-engineering-perspectives › split-string-javascript
How to Split a String in JavaScript | Built In
It can be used for tasks like parsing ... on the number of splits. In JavaScript, the split() method allows you to split the string into an array of substrings based on a given pattern....
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › string › split(string regex) method example
Java String split(String regex) method example
October 1, 2019 - This java tutorial shows how to ... package. This method returns a character array which corresponds to the result of splitting the String object given a java regular expression as a method parameter....
🌐
Apache
beam.apache.org › releases › javadoc › 2.7.0 › org › apache › beam › sdk › transforms › Regex.Split.html
Regex.Split (Apache Beam 2.7.0)
Depending on the Regex, a split can be an empty or "" string. You can pass in a parameter if you want empty strings or not. ... getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validate · clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait · public Split(java.util.regex.Pattern pattern, boolean outputEmpty)