Regular Expressions 101

Community Patterns

There does not seem to be anything here

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?<protocol>https?)?:?(?<slash>\/\/)(?<host>[a-zA-Z0-9]+[\.]+[a-zA-Z0-9-.]+)(?<port>:\d+)?(?<path>[a-zA-Z0-9\/]+.*)?$
/
gmi

Description

Can be used to test the validity of an external resource

`` function isExternalUrlResource($url) { if(preg_match('!^(?<protocol>https?)?:?(?<slash>//)(?<host>[a-zA-Z0-9]+[.]+[a-zA-Z0-9-.]+)(?<port>:\d+)?(?<path>[a-zA-Z0-9/]+.*)?$!i', $url, $matches)) { return isset($matches['host']) && isset($matches['path']); }

    return false;
}``
Submitted by Eolia - 7 days ago (Last modified 7 days ago)