Jump to content

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


with a Regular Expression this is what I have so far


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.

Link to comment
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.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...