Can you use l3regex / \regex_replace_all:nnN for replacing each explicit character token of category 11(letter) in a token list by its category 12(other) pendant? Or by its category 6(parameter) pendant?
More generalized: Can you use l3regex / \regex_replace_all:nnN for replacing each explicit character token of a certain category in a token-list by its pendant of another category?
(Leave scenarios aside where this would lead to tokens of the token-list containing unbalanced braces at some time of the processing.)
If so: How? What must the replacement text with \regex_replace_all:nnN look like?
If not: Never mind. I will write my own replacement-routine. ;-)
As expected by me the example below does not work out—\scratchy_showloop:n reveals that after the regexp-replace the token-list still contains "letters"=character tokens of category 11, and not "characters"=character tokens of category 12.
(I deliver this minimal example for satisfying those who insist in seeing a minimal example.)
\ExplSyntaxOn
\tl_new:N \l__scratchy_tl
\cs_new:Nn \scratchy_showloop:n {
\quark_if_recursion_tail_stop:n {#1}
\cs_show:N #1
\scratchy_showloop:n
}
\tl_set:Nn \l__scratchy_tl { abcdefg }
\regex_replace_all:nnN { \cL. } { \cO(\0) } \l__scratchy_tl
\exp_args:NnV \use:nn \scratchy_showloop:n \l__scratchy_tl \q_recursion_tail \q_recursion_stop
\stop
\stringbefore each found character then edef the whole list at the end – David Carlisle Feb 02 '22 at 09:01\foodefined as\def\foo#1{\Ucharcat{\#1}{6}}` (more or less) – David Carlisle Feb 02 '22 at 11:09\__diez_detokenize_loop:wis quite similar to\__zbp_loop:win the other answer). I'm not familiar with tokcycle, but I know one big difference is that tokcycle is not expandable, so that may be a no go depending on the application. Other than that, I think it serves the same purpose – Phelype Oleinik Feb 02 '22 at 11:33\ReplicateEveryHashwhich leaves spaces in place. However as a side-effect it replaces explicit character tokens of category 1/2 by explicit{/}of category 1/2 which might bite you in edge-case-scenarios. ;-) – Ulrich Diez Feb 02 '22 at 11:33\diez_detokenize:n? ;-) – Ulrich Diez Feb 02 '22 at 11:36\detokenizedoes. Then I added four random letters to the name so it is not confused with the primitive ;-) – Phelype Oleinik Feb 02 '22 at 11:38etlpackage has a macro to do the task similar-to-tokcycle expandably, but if expandable is a requirement then it has the same limitation of active-character-let-equal-to-other-character, see the answer to expansion - Define an expandable function for comparing a token list to a string in LaTeX3 - TeX - LaTeX Stack Exchange. – user202729 Feb 02 '22 at 12:10