I am trying to use a combination of Latex and sage to create tasks for my pupils. Therefore I have to replace two different types of expressions
2*x shall become 2 x
and
x*3 shall become x\cdot 3
\documentclass[utf8,fleqn]{scrartcl}
\usepackage{l3regex}
\begin{document}
\ExplSyntaxOn
\tl_set:Nn \l_my_tl { 2*x-x*4 }
\regex_replace_all:nnN { [a-z]\*\d+ } { \1 \c{cdot} \2 } \l_my_tl
$\l_my_tl$
\end{document}
This gives me 2*x-\cdot instead of 2*x-x\cdot 4
My question is, how can I refer to the separate matches found by l3regex?