0

Possible Duplicate:
Regular Expression to match outer brackets
Can I use Perl regular expressions to match balanced text?

i would like to extract a whole text which has matching numbers of closing brackets. Here is the example text.

Big String 1 {sub string 1 {{something} something {}} sub string 2{something} sub string {{something}{something else}}}

Is there an easy way for me to extract whole string which belongs to Big String 1 only? The results i would like to have is as such:

Big String 1 = "sub string 1 {{something} something {}} sub string 2{something} sub string {{something}{something else}}"

Thanks,

Community
  • 1
  • 1
mkt2012
  • 241
  • 1
  • 3
  • 8
  • How about [Text::Balanced](http://search.cpan.org/perldoc?Text::Balanced)'s `extract_bracketed`. – derobert Jan 11 '12 at 21:50
  • 1
    Matching brackets is not something that can be done with regex generically. Do you have any specific constraints (like you know the exact level of nesting)? Otherwise you will need to try a different approach. – Dean Povey Jan 11 '12 at 21:51

0 Answers0