paullos has asked for the wisdom of the Perl Monks concerning the following question:

An example code would be :
$str = "phone"; $str =~ /(..one|[gn]one)/; print "string match = $1\n "; print "expression match = ????\n ";
$1 will give the string that matched "phone" but what will give (if anything) the expression that was matched "..one" ??

Replies are listed 'Best First'.
Re: Can you get the
by Flexx (Pilgrim) on Sep 06, 2002 at 10:12 UTC

    Hi, I guess you did something wrong to your title, please read How (Not) To Ask A Question and Before You Post ....

    About your (quite unclear) question: If you need this for a finite number of static patterns an approach like

    my $str = "phone"; my @regexes = (qr/..one/, qr/[gn]one/); foreach my $regexp (@regexes) { print "$regexp matched!\n" if $str =~ $regexp; }

    could do.

    So long,
    Flexx