Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
((?:(?:https?):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:[a-z0-9][a-z0-9\-]*?[a-z0-9]+)(?:\.(?:[a-z0-9\-])*[a-z0-9]+)*(?:\.(?:[a-z]{2,})(:\d{1,5})?))(?:\/[^\s]*)?)(?:[ ]+[^< ]|\Z|\n)
/
ig

Description

Will extract URLs from text string if they have a space or line ending at the end and are not wrapped inside a string delimiter

Submitted by pip - 9 years ago