Reputation: 2646
I am using powershell, if that matters.
Let's say I have
$s = "One two (three) four \(five\) six (\(seven\)) eight"
I want a regex that will return
three
(seven)
I need all matches, and I know how PowerShell stores the matches in $matches, similar to perl's $1 $2 $3 (but that's the easy part).
Upvotes: 0
Views: 48
Reputation: 174696
Use the below regex and get the string you want from group index 1.
(?<!\\)\(((?:\\[()]|[^()])*)\)
Negative lookbehind (?<!\\)
which asserts that the match wouldn't be preceded by \
symbol.
Upvotes: 1