I have rows with different sets of parenthesis. For example
(sdfsfs) (sfdsfd)
(sdfsfs) (sfdsfd) (sfdsfd)
(sdfsfs) (sfdsfd) (sfdsfd) (sfdsfd)
This is a better solution.
while ( $text =~ //(?m)^(?=(?:.*?(?&parens)){2})(?!(?:.*?(?&parens)){3}).+$(?(DEFINE)(?\([^)\n]*\)))/g )
{
print $&,"\n";
}
Formatted:
(?m) # Multi-line mode
^ # BOL
(?= # Must be 2 paren's blocks
(?:
.*? (?&parens)
){2}
)
(?! # Cannot be 3 paren's blocks
(?:
.*? (?&parens)
){3}
)
.+ # Get the entire line
$ # EOL
(?(DEFINE)
(? \( [^)\n]* \) ) # (1)
)