LPM: Regexps for email.

David Hempy hempy at ket.org
Wed Jan 26 10:52:56 CST 2000


At 10:09 AM 1/26/2000 -0600, Ben Vandgrift wrote:
>I am using the following rexexp:
>$inline =~ s/\b(\w+\@\w+(\.\w+)*\.\w+)\b/<a href=\"mailto:$1\">$1<\/a>/g;
>
>The problem is, it continues matching on the line.  Hence, I get three
>nested requests.  Cool, but not useful.  How can I tell the regexp engine
>not to attempt a match on the text that it just inserted?

I'm not a regex guru by any means, but I don't think that it reprocesses
the substituted text with the /g modifier.  When I run this:

>$inline = "Mail me at hempy\@ket.org. Thanks!";
>print "Before: $inline\n";
>$inline =~ s/\b(\w+\@\w+(\.\w+)*\.\w+)\b/<a href=\"mailto:$1\">$1<\/a>/g;
>print "After: $inline\n";

I get this:

>Before: Mail me at hempy at ket.org. Thanks!
>After: Mail me at <a href="mailto:hempy at ket.org">hempy at ket.org</a>. Thanks!

Any chance you are processing the string twice?  It might be fruitful to
print the string before and after your regex.  Or you could even use the
debugger, but that's for sissies and smart people, of which I am neither.  ;-)

-dave


--
David Hempy
Internet Database Administrator
Kentucky Educational Television




More information about the Lexington-pm mailing list