given the following string:
foo().bar(norf.qux).fubar()
I want to split it by the dots except when they're within parentheses, where the output would be:
foo()
bar(norf.qux)
fubar()
is this possible?
given the following string:
foo().bar(norf.qux).fubar()
I want to split it by the dots except when they're within parentheses, where the output would be:
foo()
bar(norf.qux)
fubar()
is this possible?
Split the input string by dot which was not enclosed within brackets.
\.(?![^()]*\))
In Java String representing this regex would be,
"\\.(?![^()]*\\))"
String[] tok = s.split("\\.(?![^()]*\\))");
System.out.println(Arrays.toString(tok));
Output:
[foo(), bar(norf.qux), fubar()]
Pattern Explanation:
\. '.'
(?! look ahead to see if there is not:
[^()]* any character except: '(', ')' (0 or
more times)
\) ')'
) end of look-ahead