Regular Expression for URI

A while ago I had a task to fix regular expression for URI. What you will do first? Right, just open StackOverflow and find right solution. But I did not find. It is sadly, isn’t it?

Test strings



  • test
  • www.foufos
  • http://www.foufos
  • http://foufos

Solution, that I purposed: ^(https?:\/\/)?(www.)?([a-z][a-z0-9]*\.)+[a-z]{2,5}(\/|(\/[a-zA-Z0-9#.&_\?=]+\/?))*$

On regex101 with test strings: URI regex

Maybe I forget something and make mistake? I will be glad to tips and corrections.

comments powered by Disqus