I am trying out this regex on this page: http://www.regular-expressions.info/javascriptexample.html
where Regex=(?:http:\/\/)?(?:www.)?facebook\.com\/([\w\-\.]*)?
and Subject String = http://www.facebook.com/xxxxxx
This returns me two matches: http://www.facebook.com/xxxxxx and xxxxxx
The same javascript I have embedded in my chrome extension, however there it shows me only one match: 'http://www.facebook.com/' . Any ideas ? Following is the code:
var re = new RegExp("(?:http:\/\/)?(?:www.)?facebook\.com\/(?:profile\.php\?id=(?=\d.*))?([\w\-]*)?"); var m = re.exec("http://www.facebook.com/xxxxx"); if (m == null) { alert("No match"); } else { var s = "Match at position " + m.index + ":\n"; for (i = 0; i < m.length; i++) { s = s + m[i] + "\n"; } alert(s); }