You could use

(?<=\S),(?!\h*\d)\h*
  • (?<=\S) Assert a non whitespace char before the comma
  • (?!\h*\d) Assert no optional horizontal whitespace chars followed by a digit
  • \h* Match 0+ horizontal whitespace chars

Regex demo | Java demo

String s = "va1, var2, aVar,var4, my_var55 DECIMAL(20,4)";
for (String element : s.split("(?<=\\S),(?!\\h*\\d)\\h*"))
    System.out.println(element);

Output

va1
var2
aVar
var4
my_var55 DECIMAL(20,4)

To not split on a comma at the end of the string, you could also assert that the comma is followed by a word char except a digit

(?<=\S),(?=\h*\b[^\W\d])

Regex demo

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top