This is similar to Change the color of capital letters and the MWE below is modelled on egreg's answer. It works up to the point of correctly changing the first character in the input string. What I now want to do is pass a second parameter indicating which character of the string to change i.e. instead of \capme{AVXxx}
I want to be able to write e.g. \capme{AVXxx}{V}
and have only the colour of the "V" change.
The initial string will have a maximum of 8 ASCII letters, it will always contain exactly one letter matching the second parameter (so, in that example, its only valid value is one of A, V or X).
I've tried to pass the first parameter to the string "s" and the second parameter to the string "l" but even hardcoding "l" as "V" isn't working.
MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{luacode}
\begin{luacode*}
function wrap(s, l)
l="[%uV]"
s=" "..s -- The first letter may also change
s=unicode.utf8.gsub(s, "([%s{])("..l..")", "%1\\colorlead{%2}")
s=unicode.utf8.sub(s,2) -- Delete leading space
tex.print(s)
end -- function wrap
\end{luacode*}
\def\capme#1{\directlua{wrap([[#1]])}}
\begin{document}
\def\colorlead#1{{\color{red}#1}}
\capme{AVXxx}
\end{document}