in reply to regex question

You must have mistyped something, try it again please!

If you want to match only the exact words, not longer strings containing them use

$_ =~ /^$words$/

The ^ states that the word must be found at the very beginning of the line, $ means the very end.

Jenda

Replies are listed 'Best First'.
Re: Re: regex question
by zigdon (Deacon) on Sep 24, 2002 at 17:34 UTC
    though don't forget that
    /^$words$/
    expands to
    /^word1|word2|word3$/
    What you probably want to do is
    /^(?:$words)$/

    -- Dan

      This will shoot in a little different direction, but I was wondering about the '?:'. dosen't that just keep the match from being placed into $_?
        (?:...) means that the paren are only used to group, but not to save the match in $1. No real difference, except it's supposed to be faster.

        See perlre for more info.

        -- Dan

Re: Re: regex question
by gnu@perl (Pilgrim) on Sep 24, 2002 at 17:37 UTC
    DOH! Thanks. I tried that b4 and it didn't work, but I just realized what I had wrong. In my 'playing around' with things I had changed /$words/ to /^$words/ then to /^^$words$/ not thinking that when the $words alternate list is placed inside [] the '|' is taken literaly and not as a seperator for the alternates.

    I just put it as /^$words$/ and things seem to be working fine.

    Thanks for your help and pointing out my 'lil mistke.