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

Re^2: Matching against list of patterns

by Schuk (Pilgrim)
on Nov 17, 2004 at 12:42 UTC ( #408382=note: print w/ replies, xml ) Need Help??


in reply to Re: Matching against list of patterns
in thread Matching against list of patterns

To get the matched pattern matched text you can simply do:

my $pattern = join '|', map "($_)", @patterns; ... if ($line =~ /($pattern)/i) { print "matched $1\n"; }
But be carefull if you want to get another matched text in this line. Somewhat it eats up all $1,$2,$3. Use $+ to get the last matched text of the line.

Schuk

Edit: Sorry HV I should learn to read more carefully.


Comment on Re^2: Matching against list of patterns
Download Code
Re^3: Matching against list of patterns
by hv (Parson) on Nov 18, 2004 at 13:07 UTC

    That shows you what text matched, not which pattern matched it.

    There's nothing wrong with it as a way of finding out what text matched, but in the node you replied to I was specifically trying to address this aspect of the root node: the whole point of this excercise is to figure out WHICH regexp matched.

    Hugo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2015-07-07 05:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls