# latex regex remove word

I am using the hyperref package and I want to make a command for writing \hrefs once with their protocol removed. For example,

• https://google.com becomes linked google.com
• http://google.com becomes linked google.com

normally to do this I could write

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\end{document}


however, it would be ideal if I could create a command that works like so

\newcommand{\uri}[1]{
\href{#1}{
% somehow remove http[s]?:\/\/ from #1
}
}


With no special characters in the URL, it's quite easy:

\documentclass{article}
\usepackage{hyperref}

\newcommand{\rhref}[1]{%
\href{#1}{\stripprotocol#1\stripprotocol}%
}
\def\stripprotocol#1//#2\stripprotocol{#2}

\begin{document}

\rhref{https://tex.stackexchange.com}

\end{document}


If you insist on using l3regex:

\documentclass{article}
\usepackage{xparse}
\usepackage{hyperref}

\ExplSyntaxOn
\NewDocumentCommand{\rhref}{m}
{
\tl_set:Nn \l_tmpa_tl { #1 }
\regex_replace_once:nnN { \A .*? // } { } \l_tmpa_tl
\href{#1}{\l_tmpa_tl}
}
\ExplSyntaxOff

\begin{document}