Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

regex testing for multiple values

by grashoper (Monk)
on Mar 10, 2008 at 15:52 UTC ( [id://673259]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to test for different account codes using a regex and can't quite get it to work as desired, keep getting a syntax error, I am not sure what is wrong so was hoping one of the esteemed monks here would give me a clue. I really need for this check to encompass multiple values and am only looking to match these 3 letter account codes and do something if there is a match.
if ($Session->{'usrSystem'} =~"?:SND|ARM|PRO|NOR|IND\"*/s)

Replies are listed 'Best First'.
Re: regex testing for multiple values
by ack (Deacon) on Mar 10, 2008 at 19:39 UTC

    I think what all these responses are trying to say is that you want something like:

    if ($session->{'usrSystem'} =~ m/(?:(?:SND|ARM|PRO|NOR|IND|) )*/s

    The (?: ) just tell the parser to not capture the matched strings (i.e., not to produce the $1.. variables).

    I presumed from your version of the Regex that you wanted to match 0 or more occurances of the 3 letter account codes (which was why you put the * in it).

    I also presume you meant to have a white-space character (or more specifically a blank) since you put a space between the \ and the "...is that right?

    I also presume that you put the /s at the end to treat the string a single line and that . will match embedded newline characters. Is that correct?

    ack Albuquerque, NM
      I don't really want the space but your other assumptions are correct,I will try your suggested statement, and post back if I have any further problems. Thank you for the help.
Re: regex testing for multiple values
by moritz (Cardinal) on Mar 10, 2008 at 15:55 UTC
    Regexes should be delimited by / ... / or start with an <m>, like this: m{SND|ARM|PRO|NOR|IND} or m/.../.

    single quotes delimit strings, not regexes.

    Update: fixed markup, Fletch++

      the usrsystem is a session variable as i am using iis and asp and activestate, I still get the syntax error not sure what I am doing wrong, what is the <c> block in your example do?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-24 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found