Regular Expressions 101

Community Patterns

Match URL (any beginning and domain extension)

0

Regular Expression
PCRE2 (PHP >=7.3)

/
((?:https?:\/\/)?(?:www\.)?(?:\S+)?(?:\.\S+)?\.(?:com|io)(?:\/\S+)?(?:\?[\S]+)?)
/
gm

Description

PS: It catches undesired strings if they have a dot in the middle, for example "test.test", because it's not checking if ".test" is a real domain extension.

You can improve the solution by checking all the possible domain extensions: https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains

Submitted by Vini Pereira - a year ago (Last modified a year ago)