Re: [ILUG] Perl regex question

From: Martin Feeney (martin at domain tuatha.org)
Date: Tue 16 Oct 2001 - 16:16:25 IST


Not the best perl in the world (I've still not had enough excuse to do
much perl), but this should do what you need:

New competition: reduce this to the minimum required:

#!/usr/bin/perl

$text = "A = ( abc ( b = def ( c = efg ) ) )
B = (abc)
C = (
        (a = abc)
        (f = ghi)
    )\n";

  $paren = qr{
    \(
    (?:
      (?> [^()]+ )
      |
      (??{ $paren })
    )*
    \)
  }x;

$text =~ s/\s//g;
while($text) {
        $text =~ /^(.*?)\s*=\s*$paren(.*)/;
        print "$1\n";
        $text = $2;
}



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:46 GMT