Regular Expressions 101

Community Patterns

Extract port from URL

1

Regular Expression
PCRE (PHP <7.3)

/
(^([A-Z]*)((:\/\/)?)([A-Z\d\.-]{2,})\.([A-Z]{2,}):(\d{2,5})?)
/
i

Description

Extracts the port from different possible forms of URL

Submitted by anonymous - 9 years ago