Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Parsing with reg ex

by kabel (Chaplain)
on Oct 23, 2002 at 04:59 UTC ( #207297=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://207297]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-04-19 22:49 GMT
Find Nodes?
    Voting Booth?