Help - Search - Members - Calendar
Full Version: Regular Expression Replace Links With Just The Url
W3Schools Forum > Server Scripting > ColdFusion
RenegadeFX
I need to be able to replace this
CODE
<a href="http://www.UrlToSite.com">Site Link</a>

with just
CODE
http://www.UrlToSite.com

with a Regular Expression this is what I have so far
CODE
<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.
Skemcin
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.com
3 = >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.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.