Ruby text expression for text in parentheses

I am looking for a regex to replace all members in parentheses if parentheses are not in square brackets.

eg.

(matches) #match
[(do not match)] #should not match
[[does (not match)]] #should not match

I current has:

[^\]]\([^()]*\) #Not a square bracket, an opening bracket, any non-bracket character and a closing bracket.

However, this still matches the words in square brackets.

I also created a ruble page of my progress: http://rubular.com/r/gG22pFk2Ld

+5
source share
2 answers

A regular expression is not going to abbreviate it for you if you can enclose square brackets ( see this related question ).

, , () (b) , .

\([^()]*\)(?![^\[]*])

- , ]. (b) - lookbehind ( 1.9 1.8), , (match)], .

, , , , .

+2

, , , /state _if_in_square_bracket ( 3).

, , . :

  • , [/[[ ]/]], , () , "not_in_square_bracket"
  • ( ), ( "" ), ( , )

, [esp]] .

+2

All Articles