MarcAllan has asked for the wisdom of the Perl Monks concerning the following question:
Monks I have a regex question I would like to ask, probably a simple answer for you gurus out there. I have an hash value returned which can be one of two strings.
Value A CDATA[Starting SITUATION1 <311446961,2559575967> for K01.K01CSYSTE5. and Value B CDATA[Starting Enterprise situation SITUATION1 <311439572,1066403668> +for K01.K01CSYSTE5.
Now, I need to match certain parts of the string and pass them off as parameters, so for example, if value A is returned, I need to match the following values from the pattern below
CDATA[Starting SITUATION1 <311446961,2559575967> for K01.K01CSYSTE5. Starting (Param 1) SITUATION1 (Param 2) K01.K01CSYSTE5 (Param 3)
So I coded the following which works for value A
if ($elementHash->{MSGTEXT} =~ /CDATA\[(\S+)\s+(\S+)\s+.+(on|for)\s+(\ +S+)\./) { $status = $1 (Which as the value "Starting") $sitname = $2 (Which as the value "SITUATION1") $type = $4 (Which as the value "K01.K01CSYSTE5") }
But I need to alter the regex pattern so I would also match param $1, $2 and $4 for value B
CDATA[Starting Enterprise situation SITUATION1 <311439572,1066403668> for K01.K01CSYSTE5.
Notice the extra bit of text "Enterprise situation" being return in value B.So what I need is a universal pattern which will match
Starting as $1 SITUATION1 as $2 K01.K01CSYSTE5 as $4
for the possibility of either VALUE A or VALUE B string being returned Hope this makes sense
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegEx pattern
by cdarke (Prior) on Aug 30, 2011 at 09:00 UTC | |
by MarcAllan (Novice) on Aug 30, 2011 at 17:27 UTC | |
|
Re: RegEx pattern
by duyet (Friar) on Aug 30, 2011 at 08:00 UTC |