I'm a beginner in Javascript, and was playing around with regular expressions.
I tried to perform some matching operation but the result is quite confusing.
All what i'm trying to do is to match every website name in :
"I go to google.com to search, to facebook.com to share and to yahoo.com to send an email."
Here's my code :
var text = "I go to google.com to search, to facebook.com to share and to yahoo.com to send an email.";
var pattern = /\w+\.\w+/g;
var matches = pattern.exec(text);
document.write("matches index : " + matches.index + "<br>");
document.write("matches input : " + matches.input + "<br>");
document.write("<br>");
for(i=0 ; i<matches.length ; i++){
document.write("match number " + i + " : " + matches[i] + "<br>");
}
And my result :
matches index : 0
matches input : i go to google.com to search, to facebook.com to share and to yahoo.com to send an email
match number 0 : google.com
Why does it match google.com only, and not the other websites ?