Ads by ProfitSence

Regular Expression for a Matching a URL

Last Updated on Wednesday 5th Oct 2022
  • 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.


					/^(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 \