bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
Business::FedEx::DirectConnect, used for estimating FedEx shipping costs (and errors), returns a response that uses quotes and commas as "delimiters:"
"F059"3,"Invalid Recipient postal code format for specified country."99,""I'm interested in parsing what comes after the "3,". I started with a funky looking:
if ($response =~ /"3,"([\w \!\@\#\$\%\*\&\(\)\-\+\=\.\/\?\,\:\;\']+)"/ +i) { $error = $1; }
I next tried a cleaner, and successful:
$response =~ /3",([^"]+.+)"/;However, I have read caveats about using the greedy .+, however the negated character class [^"] seems to save me.
Is there a faster/safer/better regex for this? Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex negation (or golf)
by ikegami (Patriarch) on Feb 20, 2007 at 04:14 UTC | |
|
Re: Regex negation (or golf)
by GrandFather (Saint) on Feb 20, 2007 at 03:20 UTC | |
|
Re: Regex negation (or golf)
by ady (Deacon) on Feb 20, 2007 at 06:33 UTC | |
|
Re: Regex negation (or golf)
by johngg (Canon) on Feb 20, 2007 at 10:28 UTC | |
by bradcathey (Prior) on Feb 20, 2007 at 15:35 UTC | |
by johngg (Canon) on Feb 20, 2007 at 15:47 UTC | |
|
Re: Regex negation (or golf)
by Skeeve (Parson) on Feb 20, 2007 at 11:07 UTC |