Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to display a configuration file in human readable form, and trying the grab a string that is contained by brackets (they won't show up when i type them in the question). How can pull the string from the bracket? Thanks.

Replies are listed 'Best First'.
Re: Grabbing a string....
by dreadpiratepeter (Priest) on Feb 14, 2002 at 23:01 UTC
    my ($innerstr) = ($str =~ /\[(.*?)\]/);

    this assumes you only want the first occurance and that there arent any stray brackets around.
    The ? after the .* tells it to do a minimal match so that is wont greedily grab to much if there is an extra close bracket after the part you want to match.

    -pete
    Entropy is not what is used to be.
Re: Grabbing a string....
by gav^ (Curate) on Feb 14, 2002 at 23:43 UTC
Re: Grabbing a string....
by vek (Prior) on Feb 15, 2002 at 12:43 UTC
    I recently had some decent success with Andy Wardley's AppConfig.