Skip to content

Instantly share code, notes, and snippets.

View MaryVPie's full-sized avatar

Mariia Pirogova MaryVPie

View GitHub Profile

Regex Tutorial. Matching an URL.

The phrase regular expressions, or regexps, is often used to mean the specific, standard textual syntax for representing patterns for matching text. One of the cases when the regexps are used is matching and searching urls. Let say, you have a task to check if an article contains url references.

Summary

This guide will specifically breakdown the components of an example regex used to match an URL:

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

Using this regex we can identify if a string is an URL: