Gossamer Forum
Quote Reply
Regex!
This is getting me really annoyed. I bet as soon as the delete function dissapears from here I will find the answer Wink

Basically, I have a URL held in $url. What I want to do is split the www.test.com/something/something/index.html part into www.test.com and /something/something/index.html.

I know how to do the normal regex thing where it would split them up with the /'s, but i need it to split after the domain.

Would the following work?

my ($start, $end) = split(/.com|.net|.co.uk|.edu/, $url);

Any ideas would be appreciated Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Regex! In reply to
Nope.

Code:
if ($url =~ m,^(http://[^/]+)(.*)$,) {
$begin = $1;
$end = $2;
}

That should do the trick :)

I tested it with a few URL's and it worked well.


Quote Reply
Re: [RedRum] Regex! In reply to
Thanks Cool

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!