Javascript Regultar Expression for matching Domains on a string

Today I had a hard time creating a regexp to match domains on a string. I wouldn't like the internauts who visit this small blog to suffer the same pain, so here's how to :

var StringWithData = " asd http://subdomain.perrohunter.com/lol/something.php asd";
re = /http://w+([.-]?[a-z]+)*.com/;
var results = re.exec(StringWithData);
alert(results[0]);

results will be an array of matches so if you only want the first match use the 0 position, else loop the array for what you need.

cheers

Sethlans
wow, comments! almost like a real blog :) ...jk

grats
  • Reply
  • Report
PERR0_HUNTER
thx, you said like a blob or what ? o_o?
  • Reply
  • Report
wallace palace
softwareeeeeee
  • Reply
  • Report
PERR0_HUNTER
wait what ? o.o?!
  • Reply
  • Report
Leave a comment
Name:
Email:
Comment: