Regular Expression for a Matching a URL

Last Updated On Sunday 18th Jul 2021
  • Regular Expression is a series of special characters which defines a search pattern in a body of text.
  • Regex, as they are referred to, derives from the mathematical concept of regular sets and are useful for specific validation purposes
  • They are universal, which means Regex can use it with any programming language.

Regex

	/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
	
  • Within the “/../” is Anchors
  • (https?:\/\/)?,([\/\w \.-]*)*\/?$/,2,6 are Quantifiers
  • (https?:\/\/)?,([\da-z\.-]+)\.,([a-z\.]{2,6}) and ([\/\w \.-]*)*\/?$/ are Groups
  • Within the “[ … ]” is Bracket Expressions
  • Character Escapes \