MrGibbage
MrGibbage

Reputation: 2646

Regex to get text from within parenthesis including delimited parenthsis

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

Answers (2)

vks
vks

Reputation: 67968

(?<!\\)\(([^)]+\))

Try this.See demo.

http://regex101.com/r/kT6vO6/3

Upvotes: 0

Avinash Raj
Avinash Raj

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.

DEMO

Upvotes: 1

Related Questions