A well-documented, easy to modify bulletproof regular expression that matches complete URLs or URL components. Components include:
[1-9]
from [0-9]
<?QUERY>
subexpression☛ The name of the captured subexpression is usually case-sensitive.
${URL}
, \1
, or its equivalent, can be used to backreference or substitute the complete URL.
\1
$1
${URL}
$+{URL}
${SCHEME} → \2
${HOSTNAME} → \3
${PORT} → \4
${PATH} → \5
${QUERY} → \6
${FRAGMENT} → \7
Plug & Play substitution/backreference alternatives
\2\3\4\5\6\7
$2$3$4$5$6$7
${2}${3}${4}${5}${6}${7}
${SCHEME}${HOSTNAME}${PORT}${PATH}${QUERY}${FRAGMENT}
$+{SCHEME}$+{HOSTNAME}$+{PORT}$+{PATH}$+{QUERY}$+{FRAGMENT}