Actually useful URL parsing RegEx


/ Published in: Regular Expression
Save to your folder(s)

Matches are as follows:

0 = protocol
1 = fqdn
2 = subdomain
3 = top level subdomain
4 = domain (blah.com)
5 = port
6 = path
7 = query string
8 = hash


Copy this code and paste it in your HTML
  1. ^(http[s]?|ftp):\/?\/?((([^\.:\/\s]*\.?)*)\.([^\.:\/\s]+\.[^\.:\/\s]+)):?([0-9]+)?([\/\w\.+]*\/?)?\??([\w\-\.]+[^#?\s]+)?\??[^#]*#?([\w\-]+)?$

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.