Regular Expressions 101

Community Patterns

URL

1

Regular Expression
PCRE (PHP <7.3)

/
(?<!=\")\b((?:http|https|ftp):\/\/)((?:(?:\w)+\.)+(?:\w)+)(:\d+)?((?:\/[\w]+)*[.\w]*\/?)((?:[\?\w\=\_\-%+!$^*\/\\@#;:]|(?:&(?!gt;)|(?:['"](?=[\w"'&#,]))))*)
/
g

Description

simple url regex which also prevents capture of a trailing ">" (the html representation of ">")

Submitted by Erich Spaker - 9 years ago