Perl Regex HELP!

david nicol whatever at davidnicol.com
Thu Aug 1 01:48:56 CDT 2002


Jason Baker wrote:
> 
> I am going nuts here!   Im trying to do, what I would think would be, a
> simple regex on a string.  I have a string that looks like this
> 
> To: user at where.com, user2 at where.com
>     user3 at where.com
> Cc: user4.here.com
> 
> What I want to do is pickup all of the email addys on the To: like,
> spanning both lines, and put them into a string. The only consistent
> string terminator is to match a line that begins with a character and has
> a colon.  I can't get the regex to work to save my own life though.
> 
> m/(^To:.*)(^*+:/$)  is what I THINK it should be, doesnt work though.  Can
> anyone help me out?

yeah, you want the /s post-regex modifier, that allows your dot to
match the end-of-line.

Also, the To: is a place-holder so you don't want to capture it.
Something like

	{
		my ($ToField) =  $Headers =~ m/To:(.*)nw/s;
	        @EMails = $ToField =~ /([w.-]+@[w.-]+)/g;
	}

might load @EMails with all e-mail addresses listed on the To: header
line even if it spans multpile header lines.  There might be a way
using the advanced regex features to combine them into one step but
it won't be as readable.

-- 
Every sentence must do one of two things:
            reveal character or advance the action. --KV




More information about the Kclug mailing list