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); } } }
🌐
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
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).
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_split.htm
Java - String split() Method
The Java String split() method is used to divide/split a string into an array of substrings. This method accepts a string representing a regular expression as a parameter, searches for the given pattern in the current string and, splits it at every
🌐
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”, ...
🌐
TutorialsPoint
tutorialspoint.com › javaregex › javaregex_pattern_split.htm
java.util.regex.Pattern.split() Method
The java.util.regex.Pattern.split(CharSequence input) method splits the given input sequence around matches of this pattern. Following is the declaration for java.util.regex.Pattern.split(CharSequence input) method. public String[] ...
Find elsewhere
🌐
Mkyong
mkyong.com › home › java › how to split a string in java
How to split a string in Java - Mkyong.com
February 9, 2022 - In Java, we can use String#split() to split a string. String phone = "012-3456789"; // String#split(string regex) accepts regex as the argument String[] output = phone.split("-"); String part1 = output[0]; // 012 String part2 = output[1]; // 3456789
🌐
How to do in Java
howtodoinjava.com › home › string › java string split() : splitting by one or multiple delimiters
Java String split() : Splitting by One or Multiple Delimiters
October 12, 2023 - For using the multiple delimiters, the regular expression should define a character class that includes all the delimiters we want to split by. The regular expression must be a valid pattern and we must remember to escape special characters ...
🌐
Java67
java67.com › 2013 › 03 › how-to-split-string-in-java-regular-expression.html
How to Split String in Java using Regular Expression | Java67
For example, if we split String "First,Second,Third" on comma and provide limit as 2 then pattern will run one time, and split() will return String array with 2 Strings, "First" and "Second,Third". Since this method accepts a Java regular expression, it throws PatternSyntaxException, if the syntax of the regular expression is invalid.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-split-strings-using-regular-expressions-in-java
How to Split Strings Using Regular Expressions in Java? - GeeksforGeeks
July 23, 2025 - First, we apply a String.split() on the given String and pass the given regex in the argument. It will return an Array of strings and we store it in the Array then we print the Array. ... // java program to split a string.
🌐
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 ...
🌐
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.
🌐
W3Resource
w3resource.com › java-tutorial › string › string_split.php
Java String: split Method - w3resource
August 19, 2022 - Java String split Method: The split() method is used to split a given string around matches of the given regular expression.
🌐
Baeldung
baeldung.com › home › java › java string › split a string in java
Split a String in Java | Baeldung
January 8, 2024 - String[] splitted = input.trim().split("\\s*,\\s*"); Here, trim() method removes leading and trailing spaces in the input string, and the regex itself handles the extra spaces around delimiter. We can achieve the same result by using Java 8 Stream features: String[] splitted = Arrays.stream(input.split(",")) .map(String::trim) .toArray(String[]::new); We can split a string into two parts by getting its midpoint and using substring() to get the separated parts...
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
4 days ago - 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 › splitting a java string by multiple delimiters
Splitting a Java String by Multiple Delimiters | Baeldung
August 7, 2025 - Learn different options for splitting an input string by multiple delimiters using regular expressions, Google Guava, and Apache Commons
🌐
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.