Salvatore Tempesta Salvatore Tempesta - 1 month ago 5x
AngularJS Question

Regex do not match content but whole searched string

I'm using this regex to match an "href" attribute in a


var href_matches = postRep.match(/href="(.*?)"/g);

The regex matches correctly the href except it returns the whole "" string.

How do I manage to get only the href value (eg. "")?


You can either run exec() on the regex :

var url_match = /href="(.*?)"/g.exec(postRep);

or remove the global flag

var url_match = postRep.match(/href="(.*?)"/);

Using String's match() function won't return captured groups if the global modifier is set.