I'm crafting many strings from a few base strings for regex-related operations, and I am wondering if there is a less verbose way to write this.
I have for my base strings:
val ALPHA = "[a-zA-Z]"
val ODD = "[13579]"
val EVEN = "[02468]"
val INEQ = "[<>]"
Strings built from these:
val S1 = to-string $ "Today's math lesson is (%_) %_ (%_|%_)" % [ODD INEQ ODD EVEN]
val S2 = to-string $ "My boat is named (%_+)" % [ALPHA]
val S3 = to-string $ "Hashed password is ((?:%_|%_|%_)+)" % [ALPHA ODD EVEN]
... (many more)
Ideally I could write something along the lines of
evaluate-template $ "Today's math lesson is ({ODD}) {INEQ} ({ODD}|{EVEN})"
I think for a problem like composing regular expressions you might want something more robust than format strings. For example, declaring a Regex type:
this program prints:
Sidenote: GNU grep doesn't like this result, so it might need tuning.