I'd like replace some words/characters using l3regex on a arbitrary variable.

Instead of doing this

\tl_set:Nn \l_myname_tl {Hello}
\regex_replace_all:nnN {(\w+)} {\1 World!} \l_myname_tl

which works, I'd like to do something like that

\cs_new_protected:cpn { l_\myname _tl } {Hello}
\regex_replace_all:nnN {(\w+)} {\1 World!} \use:c {l_\myname _tl}

I've an error saying I've an extra parenthesis }. I'm not very familiar with LaTeX3 but If I understand well, the problem comes from the \use:c {l_myname _tl} not considered as an single token (no braced) as expected by :nnN.

What is the way of doing that ?

Thanks in advance.

1 Answer 1


You can define a variant:

\cs_generate_variant:Nn \regex_replace_all:nnN { nnc }

so you can call

\tl_set:cn { l_ \myname _tl } {Hello}
\regex_replace_all:nnc {(\w+)} {\1 World!} {l_ \myname _tl}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.