[thelist] ASP regex backreference

Simon Willison cs1spw at bath.ac.uk
Tue Sep 30 18:32:44 CDT 2003


Sam Carter wrote:

> I have an automated server-side ASP script that receives email and examines
> the bodytext for name, email and manager's email.  The syntax is something
> like:
> 
> Name: John Doe
> Email: MyEmail at whazzat.com
> Cc: MyBoss at whazzat.com
> 
> Problem is, users will send the email without the prefix Name:, Email: and
> CC: so the ASP script will receive something like
> 
> John Doe
> MyEmail at whazzat.com
> MyBoss at whazzat.com
> 
> The little parser I've written requires the keywords.
> 
> I could assume line 1, line 2, line 3 for the three elements,  but there are
> exceptions , generally caused by extra line feeds / carriage returns, or
> missing line feeds / carriage returns.
> 
> I hope Regex will come to the rescue.

I don't entirely understand the problem, but it seems to me like regular 
expressions would cause more problems than they would solve in this 
case. Instead, I would use simple string operations. I would read in the 
data as separate lines, skipping any blank lines. Then I would check for 
colons in each of those lines - if they exist the line can by split on 
the colon and understood that way. If they aren't there I would guess if 
a line contained an email address by checking if it had an @ sign in it.

To come up with a proper solution though I would need to know full 
details of the expected inputs for the script.

Cheers,

Simon



More information about the thelist mailing list