I want to split a string with the following patterns:
abc3xab -> ('abc', '3xa', 'b')
abc3x3xab -> ('abc', '3x3x', 'ab')
abc3xxab -> ('abc', '3xx', 'ab')
abc34xxab -> ('abc', '34xx', 'ab')
abc100ab -> ('abc100ab')
abc10axb -> ('abc10axb')
That's it, the pattern is '[0-9]+x[a-z]' (if there's a number followed by an 'x'
and any char between a-z
.
I tried
String[] words = string.split("[0-9]+x")
but then I only got abc
and ab
. What would be the correct way to do it?