CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Simple substitution

 



steve
Deleted

Apr 26, 2000, 8:18 AM

Post #1 of 3 (542 views)
Simple substitution Can't Post

Why doesn't this work? I am simply trying to replace anything that looks like an e-mail address with HTML link.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# $staff =~ s/(.+@.+\..+)/<a href="mailto:$1">$1<\/a>/gi;
</pre><HR></BLOCKQUOTE>

Thanks,
Steve


Peter Van Hoecke
Deleted

Apr 27, 2000, 12:10 AM

Post #2 of 3 (542 views)
Re: Simple substitution [In reply to] Can't Post

This soes the trick

$staff =~ s/( \S+\@\S+\.\S+ +)/ <a href="mailto:$1">$1<\/a> /gi;

(Perhaps you could drop the \. )

the . matches any single character except the newline, so you got to use S, which is a non white-space character.

Don't you just love regular expressions?
Peter.Van_Hoecke@ecom.be


Peter Van Hoecke
Deleted

Apr 27, 2000, 12:26 AM

Post #3 of 3 (542 views)
Re: Simple substitution [In reply to] Can't Post

Actually this is better, and to prove my point copy the $staff html in a file (test.html), look at it, run this code with a redirect to this file (perl script.pl > test.html) and hit the reload.

#!perl.exe
use strict;
my($staff);
$staff = "<HTML>
<HEAD>
<TITLE>Untitled.html</TITLE>
</HEAD>
<BODY BGcolor=#e5e5e5>
<PRE>
Yo everybody,
This could me a valid e-mail to Peter\@myself!
Peter.Van_Hoecke\@ecom.be is mijn e-mail
</PRE>
</BODY>
</HTML>";
print "$staff\n\n";
$staff =~ s/(\S+\@\S+\w)/<a href="mailto:$1">$1<\/a>/gi;
print $staff;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives