Tex compilation after regex replace

I wouldn't use \regex_replace:nnN for this job.

My suggestion is to split the input at the semicolons; then apply to each item a command for the arrow and finally use the sequence with the desired space between items.

The arrow making function uses the fact that you have two items separated by a comma, so it's good input for a clist.

\documentclass[a4paper,11pt]{article}

\usepackage{expl3,xparse}
\usepackage{textcomp}

\ExplSyntaxOn
\NewDocumentCommand{\midarrow}{m}
 {
  \seq_set_split:Nnn \l_magguu_arrows_in_seq { ; } { #1 }
  \seq_set_map:NNn \l_magguu_arrows_out_seq \l_magguu_arrows_in_seq
   { \magguu_arrows_make:n { ##1 } }
  \seq_use:Nn \l_magguu_arrows_out_seq { \hspace{1cm} }
}
\cs_new_protected:Nn \magguu_arrows_make:n
 {
  \clist_item:nn { #1 } { 1 }
  \textrightarrow
  \clist_item:nn { #1 } { 2 }
 }
\ExplSyntaxOff

\begin{document}

\midarrow{a,A;b,B;c,C}

\end{document}

enter image description here

It is immaterial if you input \midarrow{a,A;b,B;c,C} or

\midarrow{
  a, A;
  b, B;
  c, C
}

You should follow special rules in the replacement text:

  • Use \c{cmd} to represent control sequence \cmd.
  • Use \cB\{ and \cE\} to represent begin and end group brace, respectively.
  • To ensure the category codes, escape every printable character other than a-zA-Z0-9. For example, use \( to represent character (, and use (...) to represent a capturing group. (Thanks for @frougon's comment.)

Therefore your example can be modified to be

\documentclass[a4paper,11pt]{article}

\usepackage{expl3,xparse}
\usepackage{textcomp}

\ExplSyntaxOn
\NewDocumentCommand{\midarrow}{m}
{
    \tl_set:Nn \l_tmpa_tl { (#1) }
    \regex_replace_all:nnN { \, } { \c{textrightarrow} } \l_tmpa_tl
    \regex_replace_all:nnN { \; } { \)\; \c{hspace}\cB\{ 1cm \cE\} \( } \l_tmpa_tl
    \tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff

\begin{document}
    \midarrow{a,A;b,B;c,C}
\end{document}

Use the document interface3.pdf, part XXVII as a thorough introduction to l3regex library.

Tags:

Expl3

L3Regex