Reputation: 119
From this string:
asdfhjlfbvj(1dszfkl)asdfjklugnnbcvklbc(2adfsfhj)fklajsdflkjasdf(3asdf)bvcxv
With this:
\\(.*?\\)
you get (1dszfkl), (2adfsfhj) and (3asdf)
How to get asdfhjlfbvj, asdfjklugnnbcvklbc, fklajsdflkjasdf and bvcxv?
Thanks!!
Upvotes: 1
Views: 217
Reputation: 371178
Match non-parentheses characters, with lookahead for (
or the end of the string:
[^()]+(?=\(|$)
https://regex101.com/r/1XOjjA/1
Or, if you can use \K
, to be more efficient, match parentheses and what's contained in them and then use \K
to forget:
(?:\([^)]+\)\K)?[^(]+
https://regex101.com/r/1XOjjA/2
Upvotes: 1