Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

(ar0n) Re: Need help comparing against a set of regexps

by ar0n (Priest)
on Mar 10, 2002 at 07:11 UTC ( #150683=note: print w/replies, xml ) Need Help??

in reply to Need help comparing against a set of regexps

my @regexes = map qr/$_/, ('hello(\w+)', 'HELLO(\w+)', Hello(\w+)'); for my $re (@regexes) { if ($string =~ $re) { print "$string matched $re\n"; } }

[ ar0n -- want job (boston) ]

Replies are listed 'Best First'.
Re: (ar0n) Re: Need help comparing against a set of regexps
by Anonymous Monk on Mar 10, 2002 at 07:22 UTC
    Is there a way to do this in Perl5? I don't have the qr// thing.

      qr was added in Perl 5.005_03. If you're running anything older than that, you should consider an upgrade, as previous versions are considered buggy.

      my @regexes = ('HELLO(\w+)', 'hello(\w+)', 'Hello(\w+)'); for my $re (@regexes) { $re =~ s!/!\/!; # escape delimiters my $eval = '$string =~ /' . $re . '/;'; if ( eval $eval ) { print "$string matches $re\n"; } }
      It's an ugly hack, and I would very much prefer it if you would promote world peace, fight hunger and help stop global warming by upgrading your version of Perl.

      [ ar0n -- want job (boston) ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://150683]
[Eily]: hu, don't tell the other French people I never tried it, I might get kicked out :P
choroba . o O ( The Czech at-sign is also edible )
[Eily]: the French @ is a mouthful I guess...
[Eily]: choroba Wikipedia gives me Zavináč which doesn't seem to translate to something edible?
[Eily]: (yes I'm very good at using question marks, thank you)
[Discipulus]: O_O frexit for you! even me i tried. it was in the arabic quarter in Granada; they offered as 'tapas' in bars. I eataly somewhere they eat ;=P Sardinia a Pulia iirc
[choroba]: Zavináč
[Eily]: choroba oh, that makes sense :)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-11-21 10:55 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.