Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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)


Comment on Re: Parsing with reg ex
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://207297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-12-19 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls