views:

80

answers:

3

Hello,

<u class="logout" href="/logout.php?h=970c9836674709e6dcdaadd094622fc5&t=1273295318" target="_top">Logout</u>

That above is what I want to search for.

I want to get h= and t= from that URL, or just get the entire url in href=""

How would I do this with regex?

A: 

You should be able to get the href with:

var array_of_matches = str.match(/href="([^"]*")/g)

Look for 'href="' then start a capture group of all non-double-quote characters, until it ends with a final doublequote. You can pull out the query arguments using more groups inside that group.

Look at this javascript regex tutorial. And the global flag to get the array of matches described in the string regex api.

Stephen
Yeah, that just gets the first url on the page. There are multiple href links
zx
@zx: Add the /g flag, edited my answer above.
Stephen
A: 
/href="[^"]+"/g
S.Mark
That gives me "undefined".
zx
@zx, `"YOURHTMLTEXT".match(/href="[^"]+"/g)`
S.Mark
A: 

This should return both h and t values:

logout.php\?h=(\w+)&t=(\w+)
rebus