I recently asked how to test if an argument is an integer using LaTeX3 (here). I am wondering how to use the same approach to test if a string correspond to a HTML color-code. Currently, I use the following:
\documentclass[varwidth = true]{standalone}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\ishtmlcolor}{>{\TrimSpaces} m m m}{
\is_html_color:eTF{#1}{#2}{#3}
}
\regex_new:N \is_html_color_regex
\regex_set:Nn \is_html_color_regex{\A\s*[0-9a-fA-F]{6}\s*\Z}
\cs_new:Nn \is_html_color:nTF{
\regex_match:NnTF \is_html_color_regex{#1}{#2}{#3}
}
\cs_generate_variant:Nn \is_html_color:nTF{eTF}
\ExplSyntaxOff
\begin{document}
\ishtmlcolor{00FF00}{TRUE}{FALSE}
\ishtmlcolor{00AABB}{TRUE}{FALSE}
\ishtmlcolor{yellow}{TRUE}{FALSE}
\end{document}
QUESTION: How to replace the regex by something way faster in terms of compile-time?
Remark: I know that some 6-letter words in English only contain A-F, like "facade" and I'm OK detecting these as HTML color codes.
\TrimSpaces
would mean you don't need the\s*
. You could also try upper (or lower) casing#1
, which would simplify your character class.