there is currently no way to do code substitutions in regular expressions. I mean there is no way to take a list of codes and substitute them with other codes or another pattern. for example,
fish replace with
maybe regex libraries need some sort of group substitution thing that can replace with a selection of patterns, like a
(?;cat|dog|fish|bird) replacing with
(;Car|SUV|Hatchback|Truck) by matching and replacing the 1st, 2nd, 3rd, or 4th item from both groups. that would make the library even more powerful. it would be nice of somebody added something like this to POSIX. some sort of alternation code replacement.
cat would be replaced with
dog would be replaced with
fish would be replaced with
bird would be replaced with
Truck. you must have an equal number of matches and substitutions on both sides.
I don't think this can be done with
$1..$9 capture groups.
those don't substitute the source group with something else (they simply copy).
this proposal would select from a
| separated list of substitutes in
(;...) to be chosen from based on which of the source items in the source list matches an selected pattern in (?;...).
If you can think of a better way to implement this, by all means put it forth.
like the regular alternation operator, alternation is greedy. it gobbles as many characters around the
| as possible.