0

I am trying to replace an image link with a text format of the link only - http://localhost/.

I came up with this regular expression but it doesn't seem to work. Most probably it's wrong. Any ideas where is the problem? The idea is to make it work for all image links on the page, not only for the link in the example. What should I put as a string in this case?

<script>
function StripImageLinks() {
var re = /^.*?a href="|" id="image".*$/g; 
var str = '<a href="http://localhost/" id="image" target="_blank"><img src="images/xls.png" width="128" height="128" alt=""/></a>';
var subst = ''; 

var result = str.replace(re, subst);
}
</script>
a.m
  • 169
  • 3
  • 11
  • 1
    [Don't parse HTML with regex!](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Biffen Mar 18 '16 at 22:03
  • 4
    Just FYI... the link to your localhost won't show up for us. It's only visible to you. – Miles Mar 18 '16 at 22:06

1 Answers1

0

sorry, i not understand that you like replace..... but maybe this is usefull

var re = /\<a .*?href=("|')(.+?)('|") .+?\<\/a>/g

in replace you can use $2 for access href... if you have a enter or tab...

var re /\<a (.|\t|\n)*?href=("|')(.+?)('|") (.|\t|\n)+?\<\/a>/g

now href is $3

i hope have helped. sorry for my english