Gossamer Forum
Home : General : Perl Programming :

Rexep Problem

Quote Reply
Rexep Problem
Hi all, i have the following thing to solve:


I want to translate something like this:
[cat]12|Text[/cat]

in

$1 = 12 (always a number)
$2 = Text (normal Text like A-Z, 0-9 and ;.-://

I have found it for a smaller one:
[cat]12[/cat]

Code:
$tmp=~ s,\[detail\]([\w/]+)\[/detail\],<a href="$1">$1</a>,g;


With this i could make a special link to an detailed page with ID 12 e.g.

Now im looking for:

1. [sign] Name of a cat | Name of the link [/sign]

so pass out: ... a href = $1>$2< ...

2. [sign] /cat1/cat2/ | Name of the link [/sign]

pass out: ... a href= $1>$2< ...


Has someone a clue how to do that?

Must be something like:
Find
1. [sign]
2. $1 = everything till the |
3. $2 = everything till [/sign]
4. [/sign]

While in case
a) $1 should be only a number (Example: detailed page)
b) $1 should be a relative link to root (Example: category page)
c) $1 should be an absolute adress (like in Forum, but with a link and a linktext)

from this new things could be done like
c) with URL for target=blank or iURL for no target
and so on.

Robert
Quote Reply
Re: [Robert] Rexep Problem In reply to
To match everything up to the pipe you'd use:

([^\|]+)

You can probably leave out the escape as the pipe is inside a character class but I can't remember so the escape won't cause any harm.

To match after the pipe you can match everything up to [ so for that...

([^\[]+)

Last edited by:

Paul: Jan 12, 2003, 4:34 PM
Quote Reply
Re: [Paul] Rexep Problem In reply to
Thank you. Do it with this:

Code:
$tmp=~ s,\[cat\]([\w/]+)\|([\w /]+)\[/cat\],<a href="$1">$2</a>,g;
$tmp=~ s,\[det\]([\w/]+)\|([\w /]+)\[/det\],<a href="/detail/$1.php">$2</a>,g;
$tmp=~ s,\[dec\]([\w/]+)\|([\w /]+)\[/dec\],<a href="/club/detail/$1.php">$2</a>,g;
$tmp=~ s,\[gal\]([\w/]+)\|([\w /]+)\[/gal\],<a href="/club/gal/showgallery.php?cat=$1&thumb=1">$2</a>,g;
$tmp=~ s,\[for\]([\w/]+)\|([\w /]+)\[/for\],<a href="/club/board/showthread.php?threadid=$1">$2</a>,g;