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.

Edited by RenegadeFX
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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...