in reply to Regex to match text in broken parens

The following code passes your tests. It uses a single if and a hash ref as a "poor man's switch":
for (@test) { if (/ .* (^|\() (.*?) (\)|$) /x and my $p = "$1$3") { print ' Match ', { ')' => 'before right paren', '(' => 'after left paren', '()' => 'in parens', }->{$p}, ": $2\n"; } }

It's not clear, though, what should happen if the parentheses were nested.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Regex to match text in broken parens
by Rodster001 (Pilgrim) on Oct 31, 2014 at 19:25 UTC
    Exactly what I was looking for, thanks! (btw, nested parens won't be a problem with the data I am working with)

      Famous last words!


      ++$anecdote ne $data