Jump to content
RenegadeFX

Regular Expression Replace Links With Just The Url

Recommended Posts

I need to be able to replace this

<a href="http://www.UrlToSite.com">Site Link</a>

with just

http://www.UrlToSite.com

with a Regular Expression this is what I have so far

<a[^<>]+href="([^<>]+)"[^<>]*>([^<>]+)</a>

and that works fine for a link with just the href but if it has anything else like style="background:#CCF;" it works but it includes the style="background:#CCF;"Any help would be Awesome.

Edited by RenegadeFX

Share this post


Link to post
Share on other sites

There are a couple ways you can go about this.You could try something pretty crazy, like reading the text as an array and then loop through it using a double quote as a delimiter.With your first example, that would produce an array with:1 = <a href=2 = http://www.UrlToSite.com3 = >Site Link</a>Once you have that defined, just use the array search function to look for "http" and you should have what you need.Now, this does assume that well formed / valid HTML has been coded since we are absolutely dependent on double quotes being used properly and all the places they should.Try it out and post your code if you run into problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×