[H-GEN] Reading signed emails using OE

Jason Parker-Burlingham jasonp at uq.net.au
Wed Jun 4 00:15:18 EDT 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

"Michael Anthon" <michael at anthon.net> writes:

> From: "Greg Black" <gjb at gbch.net>
>>I wonder how it would go if you changed the sed substitute
>>command to this:
>>   's/.*boundary="\(.*\)".*/\1/'

> I was hesitant to use the regex as you wrote it (pretty much what I
> originally had in my first pass) since I've been stung before with the
> greediness factor in regex.  For example, suppose we had a header like
>
> Content-Type: multipart/signed; boundary="Qo8f1a4rgWw9S/zY";
> micalg="pgp-sha1"
>
> Will the first .* in your regex match Qo8f1a4rgWw9S/zY, Qo8f1a4rgWw9S/zY";
> micalg= or Qo8f1a4rgWw9S/zY"; micalg="pgp-sha1
> I believe it probably matches the last one but I don't know that it is
> always the case so I used [^"]+ instead.

I like to use the "([^"]+)" form myself for just that reason.

> You could probably also force the greediness of the correct pattern
> as well to achieve the same result (or is greediness just a perl
> thing? I can't find any reference to it in the standard regex doco)

I'm not aware that any other regular expression engines implement the
+? and *? modifiers but then I tend not to use many other regex
implementations.

However!  As was recently pointed out on comp.lang.perl.misc, changing
the greediness of part of a regular expression doesn't change what
will (eventually) be matched.  Rather it is a hint to the regex engine
to try certain matches before certain other matches.  

Since a regex returns the first match found, this has the effect of
getting different results, but it does mean it can't, as a rule, be
relied upon to achieve the same effect as the idiom above.
-- 
Stay up-to-date on what I'm doing lately:
                                 http://www.netacc.net/~burlingham

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list