Regex javascript for href matching

Exit

This is what I want to find.

I want to get h = and t = from this url or just get the whole url in href = ""

How do I do this with a regular expression?

+2


a source to share


3 answers


You can get href

with:

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

      



Look for "href =" ', then run a group to capture all non-double-quoted characters until it ends with a final double-quote. You can output query arguments using more groups within this group.

Take a look at the javascript regex tutorial . And a global flag to get the array of matches described in the string regex api .

+5


a source


/href="[^"]+"/g

      



0


a source


This should return values h

and t

:

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

      

0


a source







All Articles