in reply to Re: regex testing for multiple values
in thread regex testing for multiple values

This node was taken out by the NodeReaper on Mar 12, 2008 at 13:38 UTC
  • Comment on Reaped: Re^2: regex testing for multiple values

Replies are listed 'Best First'.
Re^3: regex testing for multiple values
by nefigah (Monk) on Mar 10, 2008 at 16:39 UTC

    The <c> block looks like an artifact from his HTML, if that's what you mean--it shouldn't show up in your code...

    That is, he was saying if you aren't going to use forward slashes to delimit your regex, then you need to prefix it with m:

     if ($blah =~ m#regex here#options here) instead of the usual  $blah =~ /regex here/options here

    or what have you. (In your post, the regex doesn't appear to start with a forward slash.)



    I'm a peripheral visionary... I can see into the future, but just way off to the side.
Re^3: regex testing for multiple values
by Not_a_Number (Prior) on Mar 10, 2008 at 19:50 UTC
    ...all I get is a syntax error mismatched right bracket

    That's not what I get when I run your snippet (commenting out the do something lines). I get:

    syntax error at [...] line 12, near "{"

    where lines 12-13 are:

    elsif {

    Did you perchance mean else rather than elsif?

Re^3: regex testing for multiple values
by proceng (Scribe) on Mar 10, 2008 at 18:24 UTC
    if ($Session->{'usrSystem'}=~/{IND|NOR|PRO|ARM|SND/s)
    I don't understand why its not executing the code block, all I get is a syntax error mismatched right bracket for now I wrote as a series of if statements its ugly but it works.
    See bolded areas.
      Update: Oh, did you want there to be a literal curly brace before IND but not the rest? If so, ignore the rest of this post.

      Yeah, you have a mismatched bracket there :) Try:
      if ($Session->{'usrSystem'} =~ /IND|NOR|PRO|ARM|SND/s)

      Note that you'll want to surround the alternations in parentheses (these kind) if you want something like:
      /^(IND|NOR|PRO|ARM|SND)/


      I'm a peripheral visionary... I can see into the future, but just way off to the side.
      Right idea, wrong bolding. It's misleading on the OP's part,but that quoted statement is not a syntax error. The trailing slash closes the regex and the right paren properly terminates the if clause. The right paren is not matching the left brace - that left brace is part of the regex and is treated as a literal.
      "Mismatched" is so hard to understand?

      Did you try taking it out?

      {...} surrounds quantifiers in regexen, like:

      =~/[A-Z](1,3}/ # Match any char in the range A-Z no fewer than once, # nor more than 3 times
        Did you try it out?

        Did you? :)

        $_ = '{IND'; print "Ok\n" if /{IND/; ____ Ok

        Update: It seems that I misquoted ww, who actually wrote 'Did you try taking it out?'. My point remains valid, though. The problem is not with the regex, it is somewhere else in the code.