Gossamer Forum
Home : Products : Links 2.0 : Customization :

Regular expressions!

Quote Reply
Regular expressions!
Hi guys
I am using Links for several different functions on my new site. I could really use your help with some regular expressions which I need to enable me to run a newsletter archive...

www.ten-tenths.com/newsletter/

I have the whole thing up and running, but I need to manually edit my newsletter after I have mailed it (using a third party script) so that all http:// and mailto: links are 'live'

What I really need is to be able to adapt the regular expression, which I currently use in sub site_html_detailed to convert a line break into a <br>, so that it will create a hyperlink in the right place.

example:

The newsletter contains the following: <http://www.ten-tenths.com/>

I want to output: <a href="http://www.ten-tenths.com/">http://www.ten-tenths.com/</a>

Is this possible ?

Currently I use this expression:

$rec{'Body'} =~ s,\n,<br>,g;

I would very much appreciated any help or assistance which anyone can offer as i'm useless with these things Frown I've searched this forum several times but have yet to find someone who has asked a similar question. The best I could come up with was this:

$rec{'Body'} =~ s,<http://,<a href="http://,g;
$rec{'Body'} =~ s,<mailto:,<a href="mailto:,g;
$rec{'Body'} =~ s,>,</a>,g;

But then I got stuck! Smile

Help!

------------------
Craig Antill
10 Tenths Links Directory - www.Ten-Tenths.com/links/
10 Tenths Multimedia Archive - www.Ten-Tenths.com/downloads/multimedia/
10 Tenths Newsletter Archive - www.Ten-Tenths.com/newsletter/
10 Tenths Toon Archive - www.Ten-Tenths.com/toons/
Parc Ferme Magazine - www.parcferme.com/
THE Directory - www.gardenbuildings.com/
Quote Reply
Re: Regular expressions! In reply to
  
Code:
$rec{'Body'} =~ s/([\w]+:\/\/[\w-?&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g

Should do it for http://, https:// and ftp:// URLs

Code:
$rec{'Body'} =~ s/(mailto:[\w-?@&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g

Might work for mailto: You'll have to try it to be sure.

Dan O.



[This message has been edited by DanO (edited March 13, 2000).]
Quote Reply
Re: Regular expressions! In reply to
DanO, thanks for the assistance!
Unfortunately i'm unable to get it to work Frown Any ideas ?

Code:
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#

my %rec = @_;
$rec{'Body'} =~ s,\n,<br>,g;
$rec{'Body'} =~ s/([\w]+:\/\/[\w-?&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g
$rec{'Body'} =~ s/(mailto:[\w-?@&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}

Quote:
Error including libraries: syntax error at /usr/www/tententh/html/newsletter/admin/site_html_templates.pl line 127, near "return"

Make sure they exist, permissions are set properly, and paths are set correctly.


------------------
Craig Antill
10 Tenths Links Directory - www.Ten-Tenths.com/links/
10 Tenths Multimedia Archive - www.Ten-Tenths.com/downloads/multimedia/
10 Tenths Newsletter Archive - www.Ten-Tenths.com/newsletter/
10 Tenths Toon Archive - www.Ten-Tenths.com/toons/
Parc Ferme Magazine - www.parcferme.com/
THE Directory - www.gardenbuildings.com/
Quote Reply
Re: Regular expressions! In reply to
You need to have semi-colons at the end of the second and third lines of the codes you added...

The complete codes should look like the following:

Code:
$rec{'Body'} =~ s,\n,<br>,g;
$rec{'Body'} =~ s/([\w]+:\/\/[\w-?&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g;
$rec{'Body'} =~ s/(mailto:[\w-?@&;#~=\.\/]+[\w])/<A HREF="$1" target=\"new\">$1<\/A>/g;

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Regular expressions! In reply to
Oh, bloody hell! I was so busy marvelling at the bit I didn't understand that I forgot the damned obvious! Smile

Many thanks to you both - appreciated!

http://www.ten-tenths.com/newsletter/Issues/68.html

------------------
Craig Antill
10 Tenths Links Directory - www.Ten-Tenths.com/links/
10 Tenths Multimedia Archive - www.Ten-Tenths.com/downloads/multimedia/
10 Tenths Newsletter Archive - www.Ten-Tenths.com/newsletter/
10 Tenths Toon Archive - www.Ten-Tenths.com/toons/
Parc Ferme Magazine - www.parcferme.com/
THE Directory - www.gardenbuildings.com/
Quote Reply
Re: Regular expressions! In reply to
You're welcome.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums