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

Re^3: regex testing for multiple values

by proceng (Scribe)
on Mar 10, 2008 at 18:24 UTC ( [id://673299]=note: print w/replies, xml ) Need Help??


in reply to Reaped: Re^2: regex testing for multiple values
in thread regex testing for multiple values

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.
  • Comment on Re^3: regex testing for multiple values

Replies are listed 'Best First'.
Re^4: regex testing for multiple values
by nefigah (Monk) on Mar 10, 2008 at 19:18 UTC
    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.
Re^4: regex testing for multiple values
by Errto (Vicar) on Mar 10, 2008 at 21:49 UTC
    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.
Re^4: regex testing for multiple values
by ww (Archbishop) on Mar 10, 2008 at 18:55 UTC
    "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.

        With chagrin, I must admit that I was thinking syntax, and testing proves me wrong on that account.

        However, grashoper is not looking for '{IND' but, rather, for "3 letter account codes...."

        If I understand that correctly, the condition in the regex in Re^2: regex testing for multiple values

        if ($Session->{'usrSystem'}=~/{IND|NOR|PRO|ARM|SND/s)

        introduces an open_curly_brace ({), which is wrong, in part, because the regex then tries first to match on for an open_curly_brace.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found