Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Complete URLs

A more complete (and slower) pattern would also match URL query strings (variable information passed to a URL and separated from the URL itself by a ?), as well as optional user login information, if specified.

http://www.forta.com/blog
https://http://www.forta.com:80/blog/index.cfm
http://www.forta.com
http://ben:password@http://www.forta.com/
http://localhost/index.php?ab=1&c=2
http://localhost:8500/
https?://(\ w*:\ w*@)?[-\ w.]+(:\ d+)?(/([\ w/_.]*(\ ?\ S+)?)?)?
http://www.forta.com/blog
https://http://www.forta.com:80/blog/index.cfm
http://www.forta.com
http://ben:password@http://www.forta.com/
http://localhost/index.php?ab=1&c=2
http://localhost:8500/

This pattern builds on the previous example. https?:// is now followed by (\ w*:\ w*@)?. This new pattern checks for embedded user and password (username and password separated by : and followed by @) as seen in the fourth line in the example. In addition, (\ ? S+)? (after the path) matches the query string, ? followed by additional text, and this, too, is made optional with ?.

  • + Share This
  • 🔖 Save To Your Account