Gossamer Forum
Home : General : Perl Programming :

Regex for url

Quote Reply
Regex for url
Hi all, i use this global for my lsql:
sub {
my $tags = shift;
my $tmp = $tags->{URL};
$tmp=~ regex
return $tmp;
}

to show the URL under each link.
While i dont want to show the whole link with dirs and files i tried to rexep some things out.

http://www.sub.domaine.com/
seems a good start for me. (1=the first, i = possible more, n=the last)

^(http://)
( ([a-z0-9\-]+) [\.] )+?
(([a-z0-9\-]+) [\.])
([a-z]+)
(/)
(.*)

While i got now:
$1 http://
$5 domaine
$6 com
$7 dirs/file

What i cant fix till now is to get
http:// thesepart . domaine.com
Quote Reply
Re: [Robert] Regex for url In reply to
Ok. Got it. BTW: Is there another way to group things without using (),
i dont need all the $1,$2 ... and it ugly to count them everytime i change things.