Chapter 88: LaTeX RegEx

\usepackage{xcolor}
\usepackage{expl3,xparse}

\ExplSyntaxOn
\NewDocumentCommand{\recolor}{m}
{
    \tl_set:Nn \l_tmpa_tl { #1 }
    \regex_replace_all:nnN { 2 } { \c{ensuremath}{\c{color}{red}{2}} } \l_tmpa_tl
    \tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff

\recolor{c^{2}=a^{2}+b^{2}}

https://stackoverflow.com/questions/2116944/insert-programming-code-in-a-lyx-document

https://tex.stackexchange.com/questions/53260/lyx-is-ignoring-typewriter-font-setting-for-program-listings

The LATEX3 Interfaces-20240220-including ExpL3,RegEx

https://tex.stackexchange.com/questions/534581/tex-compilation-after-regex-replace

https://www.overleaf.com/project/66512b6948077364474110de

\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}

\[ \require{expl3,xparse} \]

{ _set:Nn _tmpa_tl { (#1) } _replace_all:nnN { , } { } _tmpa_tl _use:N _tmpa_tl }

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

{ _set:Nn _tmpa_tl { #1 } _replace_all:nnN { } { {{red}{\0}} } _tmpa_tl _use:N _tmpa_tl }

\[ \recolor{\begin{aligned}\boldsymbol{\omega}= & \left[\boldsymbol{\omega}\right]^{{\scriptscriptstyle V}}V^{*}=\left[\boldsymbol{\omega}\right]^{{\scriptscriptstyle \tilde{V}}}\tilde{V}^{*}\\ = & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}V^{*}{}^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle k}}=\omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}\tilde{V}^{*}{}^{{\scriptscriptstyle j}}{}_{{\scriptscriptstyle k}}\\ \omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}\tilde{V}^{*}{}^{{\scriptscriptstyle j}}{}_{{\scriptscriptstyle k}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}V^{*}{}^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle k}}\\ \omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}V^{*}{}^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle k}}\left(\tilde{V}^{*}{}^{{\scriptscriptstyle j}}{}_{{\scriptscriptstyle k}}\right)^{{\scriptscriptstyle -1}}=\omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}V^{*}{}^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle k}}\left(\tilde{V}^{*}{}^{{\scriptscriptstyle -1}}\right)^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle j}}=\omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\\ \boldsymbol{\omega}\left(\tilde{\boldsymbol{v}}_{{\scriptscriptstyle j}}\right)=\omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=\boldsymbol{\omega}\left(\boldsymbol{v}_{{\scriptscriptstyle i}}\right)Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=\boldsymbol{\omega}\left(\tilde{\boldsymbol{v}}_{{\scriptscriptstyle k}}B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle i}}\right)Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=\boldsymbol{\omega}\left(\tilde{\boldsymbol{v}}_{{\scriptscriptstyle k}}\right)B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle i}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\\ \boldsymbol{\omega}\left(\tilde{\boldsymbol{v}}_{{\scriptscriptstyle j}}\right)= & \boldsymbol{\omega}\left(\tilde{\boldsymbol{v}}_{{\scriptscriptstyle k}}\right)B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle i}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\\ B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle i}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}= & \delta^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle j}}\Rightarrow Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=F^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\\ \omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}Q^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=\omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}F^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\\ \omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}F^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}\Rightarrow\begin{bmatrix}\vdots\\ \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}\\ \vdots \end{bmatrix}^{{\scriptscriptstyle \intercal}}=\begin{bmatrix}\vdots\\ \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}\\ \vdots \end{bmatrix}^{{\scriptscriptstyle \intercal}}F\\ \omega_{{\scriptscriptstyle k}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle j}}= & \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}F^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle k}}B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle j}}=\omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}\delta^{{\scriptscriptstyle i}}{}_{{\scriptscriptstyle j}}=\omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \boldsymbol{v}}}\\ \omega_{{\scriptscriptstyle j}}^{{\scriptscriptstyle \boldsymbol{v}}}= & \omega_{{\scriptscriptstyle k}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}B^{{\scriptscriptstyle k}}{}_{{\scriptscriptstyle j}}\Rightarrow\begin{bmatrix}\vdots\\ \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \boldsymbol{v}}}\\ \vdots \end{bmatrix}^{{\scriptscriptstyle \intercal}}=\begin{bmatrix}\vdots\\ \omega_{{\scriptscriptstyle i}}^{{\scriptscriptstyle \tilde{\boldsymbol{v}}}}\\ \vdots \end{bmatrix}^{{\scriptscriptstyle \intercal}}B \end{aligned} } \]