I would like to suppress a character from a hyperref link that is built via \url, but the textual representation should keep that character. For example, if the character is *, I want \url{http://tex.stackexchange*.com} act as \href{http://tex.stackexchange.com}{http://tex.stackexchange*.com}.
An embarrassingly failing attempt to hack the \hyper@linkurl macro is given in the MWE, just to show some effort.
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\makeatletter
\renewcommand\hyper@linkurl{%
\begingroup
\lccode`\~=`\*\relax
\lowercase{\def~}{}%
\catcode`\*\active
\lccode`\~=0\relax
\my@hyper@linkurl
}
\def\my@hyper@linkurl#1#2{%
\edef\x{\toks0={#2}}\x
\Hy@pstringdef\Hy@pstringURI{\the\toks0}%
\hyper@chars
\leavevmode
\pdfstartlink
attr{%
\Hy@setpdfborder
\ifx\@pdfhightlight\@empty
\else
/H\@pdfhighlight
\fi
\ifx\@urlbordercolor\relax
\else
/C[\@urlbordercolor]%
\fi
}%
user{%
/Subtype/Link%
\ifHy@pdfa /F 4\fi
/A<<%
/Type/Action%
/S/URI%
/URI(\Hy@pstringURI)%
\ifHy@href@ismap
/IsMap true%
\fi
\Hy@href@nextactionraw
>>%
}%
\relax
\Hy@colorlink\@urlcolor#1\Hy@xspace@end
\close@pdflink
\endgroup
}
\makeatother
\url{http://tex.stackexchange*.com}
\end{document}
This is trying to make the star active, and let it be replaced by an empty group in the assignment to toks0, but it does not work. It also does not feel right to replicate so much code from hyperref. What is a better way to achieve this?

\Urlmacro? – Qrrbrbirlbel Mar 22 '13 at 23:13\hrefversion? (Also, I actually would be interested in the purpose of your aim.) – Speravir Mar 22 '13 at 23:30\urlare coming frombblfiles, formed from user provided URLs. So they are pretty much given. The * shall remain in the link text to be treated with\UrlSpecialfor line breaking. – mafp Mar 22 '13 at 23:37\UrlSpecial. Herbert's solution is all fine, but what I ultimately want to achieve is selective line breaking of the link text, e.g., allow breaks after some periods, say, but not after all of them. – mafp Mar 23 '13 at 00:21