I recently came across a site that made coming up with regular expressions much, much easier for me: <span style="font-family:'.HelveticaNeueUI';white-space:nowrap"><a href="http://www.debuggex.com/">http://www.debuggex.com/</a></span><div>
<font face=".HelveticaNeueUI"><span style="white-space:nowrap"><br></span></font></div><div><font face=".HelveticaNeueUI"><span style="white-space:nowrap">Hopefully that will help with your "regex hell" problem.<span></span><br>
</span></font><br>On Thursday, July 18, 2013, Greg Hendershott wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To add to what Carl and Robby said:<br>
<br>
On Thu, Jul 18, 2013 at 2:29 AM, <<a href="javascript:;" onclick="_e(event, 'cvml', 'm0nastic@tengulabs.com')">m0nastic@tengulabs.com</a>> wrote:<br>
> (although truth be told, mail headers are surprisingly nonstandard even<br>
> within a single message)<br>
<br>
That's where net/head could definitely help. (Especially for SMTP<br>
headers, which tend to be more "interesting" than typical HTTP<br>
headers.)<br>
<br>
> I eventually discovered that I could sort of cheat, by just wrapping the<br>
> regexp-match function with a car (which worked, because this particular<br>
> list only had one element), and then it was usable from then on (and<br>
> validated true from "string?").<br>
<br>
It's worth walking through what Carl described. Actually you're lucky,<br>
you have a specific example of something you want to do, which touches<br>
on a few basic aspects of Racket.<br>
<br>
Having said that, one pattern I've settled into using with regexps is<br>
to use `match`, which makes it convenient to "de-structure" the list.<br>
For example:<br>
<br>
(match "From: Me"<br>
[(pregexp "^(.+):\\s*(.+)$" (list all key val))<br>
(displayln all) ; From: Me<br>
(displayln key) ; From<br>
(displayln val)]) ; Me<br>
<br>
If you don't need the "all" part, you can supply _ like so:<br>
<br>
(match "From: Me"<br>
[(pregexp "^(.+):\\s*(.+)$" (list _ key val))<br>
(displayln key)<br>
(displayln val)])<br>
<br>
Which is the pattern I use a lot.<br>
<br>
Again, you probably want to use net/head to deal with the gory details<br>
of SMTP headers as Robby suggested, and it would definitely be good to<br>
walk through the explorations Carl described.<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div>