Skip to content

Files

Latest commit

26a1f75 · Aug 8, 2018

History

History
23 lines (14 loc) · 618 Bytes

regex.md

File metadata and controls

23 lines (14 loc) · 618 Bytes

Regular expressions

Regex for finding URLs

Regex if you want to ensure URL starts with HTTP/HTTPS:

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

If you do not require HTTP protocol:

[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

Exemple usage in VSCode to find a URL and convert to Markdown link like, [link](link):

Find: (https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))

Replace: [$1]($1)

Use () to create a group and $1 to reference that group.