Fr*********@gmail.com writes:
How can I strip out the text from within this "href" attribute?
Here is the input:
<span href="/test.htm¶meter=2"></span>
What I'd like to get back is:
/test.htm¶meter=2
Well, that's easy:
function getHref(input) {
return "/test.htm¶meter=2";
}
But seriously, you should be very careful to know exactly what can
vary in the input. Is it always a span element (unlikely, since
they don't have href attributes)? Is it always the href attribute
you need? And is it always contained in double quotes?
Let's assume that you are looking for just one href attribute where
the value is in double quotes. Then the following regular expression
will capture that:
var re = /\bhref="([^"]*)"/;
In a function it would be:
function getHrefRE(input) {
var re = /\bhref="([^"]*)"/;
var match = input.match(re);
if (match) {
return match[1];
}
}
If the quotes can be either single and double quote, a regexp might
be:
var re2 = /\bhref=(['"])([^\1]*)\1/;
where the content is match[2].
Good luck
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'