By using repr(), you can learn more about what kinds of character you need to replace:
(note that I added "a" and > to the equation as well to learn more about the kinds of contents)
#repr($"ABCDabcd" "a" a > b c d$)
// equation(
// block: false,
// body: sequence(...),
// )",
#$"ABCDabcd" "a" a > b c d$.body.children.map(x => {
(x, x.func())
})
// (
// ([ABCDabcd], text),
// ([ ], space),
// ([a], text),
// ([ ], space),
// ([a], symbol),
// ([ ], space),
// ([>], symbol),
// ([ ], space),
// ([b], symbol),
// ([ ], space),
// ([c], symbol),
// ([ ], space),
// ([d], symbol),
// )
You can see that there are three kinds of content in there: text (that you don’t want to format), space, and symbol (the content of interest). That symbol is a math element function, and not the same as the symbol type! A bit confusing, but we can work with that.
Your previous approach would style the "a": it is a single character, but not italic as it is not a math symbol. Here’s a show rule that, as far as I understand your requirements, works:
#show math.equation: it => {
// we need to refer to the symbol element function somehow
let math-symbol = $a$.body.func()
// match all symbols
show math-symbol: it => {
// style if it's a lowercase letter
set text(red) if it.text.match(regex("^[a-z]$")) != none
it
}
it
}
$"ABCDabcd" "a" a > b c d$
