Gossamer Forum
Home : General : Perl Programming :

Regex problem

Quote Reply
Regex problem
Hi all,
i use this in my description to have a shortcut to enter for something longer:
If i write [Test] in the field i go on with a global to get:

Code:
$tmp=~ s/\[Test\]/<a href='\/test\/index.php?s>More in the test area<\/a>/;
This is quite nice, but better would be to do something like:

[Test/5]
then i need something that:
1. See that there is [Test and a number] with / to divide them;
then i want have something like
Code:
<a href="/test/NUMBER.php ...
My english is not the best so i try it once again.
In my example i translate [Test] in a certain link, i do this not to write the whole link every time, i want it inside a description.
This is possible while i use a global fDescription that search for [Test] in Description and returns fDescription with the translation in it.
In my templates i use now fDescription instead Description.

Now i want to pass not only one certain link, but a number e.g. 234, too.
So i want to use [Test/234] to be in fdesrcription something like:
Code:
<a href="/test/234.html" ...


1. Problem, how to get [Test/$] with rexep; should be in $1, i think.
Then i need a spli with / to get $a1=Test, $a2 = my number;
with this i could do

if $a1 = Test then write /Test/$a2.html

Hope someone understands my problem and could help.
Thank you.
Robert
Quote Reply
Re: [Robert] Regex problem In reply to
Code:
my $tag = '[testing/123]';

if ($tag =~ m|^\[([^/]+)/(\d+)\]$|) {
$url = qq!<a href="/$1/$2.html">!;
}

Something like that I guess. You may also want:

Code:
if (-e $url) {

To make sure the file exists.

Last edited by:

Paul: Sep 27, 2002, 6:20 AM