Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
([(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b([-a-zA-Z0-9@:%_\+~#?&\/\/=]*)|(http(s)?:\/\/\/?)
/
mgi

Description

Search text for any URL, including numerical IPs and greater than 3 char domain extensions. Also searches for http(s) alone, include with a third slash, as I ran into scumbag Russian spammers who were doing this.

Submitted by J. Scott Elblein - 6 years ago