I want to do string substitution. With gsub
or tr
I can give a single input character and map it to a single output value but I want to create multiple output strings based on multiple mappings:
swap = {
'a' => ['$', '%', '^'],
'b' => ['3'],
'c' => ['4', '@'],
}
For input string 'abc'
, I should get the following output strings:
'$34'
'$3@'
'%34'
'%3@'
'^34'
'^3@'
Is there an easy way to do this for an arbitrary number of inputs and mappings? In reality it is likely to be about 10 inputs and at most 3 mappings, usually only one.