in reply to Parsing with reg ex

this code does not find particular tokens, it just finds anything inside parenthesis and prints it out. this is meant to be a startingpoint.

use strict; use warnings; # # slurp file # my $file_contents = ""; { local $/; $file_contents = <DATA>; } # # "parse" file # while ($file_contents =~ m/\((.*?)\)/sg) { my $match = $1; $match =~ s/\n//g; print "[$match]\n"; } __DATA__ prematch (match) postmatch adsf (madfa tch) asdf

the meaning of the special variables can be found in perlvar.
also have a look inside the tutorials section.

UPDATE: added backreferencing () for $1 (thx to robartes)

Replies are listed 'Best First'.
Re: Re: Parsing with reg ex
by ByteOrNybble (Novice) on Oct 25, 2002 at 03:02 UTC
    So your code could also work for * or % or whatever... it would just be a matter of changing the symbol, right? Thank you.