Hi Eckhart

This is a very tricky problem that your unlikely to be able to solve using a
single regex. 

Have you tried Damien's Conway's Text::Balanced or Parse:RecDescent
http://cpan.valueclick.com/authors/id/D/DC/DCONWAY/

There's a good discussion of this problem in Mastering Algorithm with Perl
(aka "The Wolf") too.

However, if you wanted to be really, really sneaky, you could reformat your
string to look like a perl list of lists (of ...) declaration, run an "eval"
to get Perl to do the parsing for you, then just walk through the
references. 

HTH

Alistair

> ----------------------------------------------------------------------
> Alistair McGlinchy,           [EMAIL PROTECTED]
> Sizing and Performance, Central IT,   ext. 5012,   ph +44 20 7268-5012
> Marks and Spencer, 3 Longwalk Rd, Stockley Park, Uxbridge UB11 1AW, UK 
> 
> -----Original Message-----
> From: eckart [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, January 14, 2002 8:31 PM
> To:   perlwin32
> Subject:      regular expr. help 
> 
> Salve,
> 
> I need some help on the following multi-line string....
> 
        CREATE REQUEST
> (
>       INVOKE IDENTIFIER 0,
                MANAGED OBJECT CLASS FAMILY,
>       MANAGED OBJECT INSTANCE
>       {
>               EntityId = "human",
>               familyId = number : 0
>       },
>       ATTRIBUTE LIST
>       {
>               familyName "MILLER",
>               addressInfo :
>               {
>               zipCode = integer : 12345,
>                       streetName = string : "Sunset Blvd."
>                       number = integer : 55
>               }
>               memberInfo :
>               {
>                       {
>                               sex = string : female,
>                               age = integer : 28,
>                               name = string : "Emily"
> 
>                       },
>                       {
>                               sex = string : male,
>                               age = integer : 29,
>                               name = string : "Bobby"
>                       },
>                       {
>                               sex = string : female,
>                               age = integer : 3,
>                               name = string : "Lisa"
>                       }
>               }
>       }
> )
> 
> I would like to find for any opening bracket '{' the matching closing
> bracket '}'.
> E.g. for the '{' after memberInfo : the second bracket '}' after "Lisa"
> should be matched and not the one after "Emily". The part of the string
> between the matching brackets has to be extracted.
> I have already a solution by counting the opening '{' and closing '}'
> brackets, but I think there is a smarter solution via regex.
> 
> Any good ideas?
> 
> Thanks
> Eckart
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users


-----------------------------------------------------------------------


Registered Office:
Marks & Spencer p.l.c
Michael House, Baker Street,
London, W1U 8EP
Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422 
Facsimile (020) 7487 2670

www.marksandspencer.com

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and 
then delete it from your system; you should not copy, disclose, or distribute its 
contents to anyone nor act in reliance on this e-mail, as this is prohibited and may 
be unlawful.

The registered office of Marks and Spencer Financial Services Limited, Marks and 
Spencer Unit Trust Management Limited, Marks and Spencer Life Assurance Limited and 
Marks and Spencer Savings and Investments Limited is Kings Meadow, Chester, CH99 9FB.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to