This should work:
String str = "/xyz/abc[bcd(text(),\"string\")]";
String[] arr = str.split("(?<=\\G(?>\\w+|\\W))\\s*");
This gives:
["/", "xyz", "/", "abc", "[", "bcd", "(", "text", "(", ")", ",", """, "string", """, ")", "]"]
Explanation:
- Regex is using \G which matches from end of last matched position
(?>..)
is an atomic group (More details: http://www.regular-expressions.info/atomic.html)