Generating all string possibilities with wildcard characters? (code golf-based)

I ran into this code golf problem on StackExchange. The premise is that you take in a short string with some wildcard characters (*) and return all of the possible variations of that string, replacing the wildcards with each letter of the alphabet. Here’s an example the original question gives:

Input:

*e*c*m*

Output:

aeacama
aeacamb
...
...
...
welcome
...
...
zezczmz

After working through some initial attempts, I realized I actually have no idea how I would solve this effectively! :sweat_smile: I’m not even interested in golfing it anymore, per se, I’m mostly looking to expand my horizons a bit.

I’d love to see some Julian approaches to this, if anyone has any—I’m especially intrigued by things like the functional Haskell solution, since I know Julia leans more functional than some other languages, but I’d love to see anything people can come up with. Could anyone demonstrate some good ways to tackle this problem?

Not very golfed but here is something to start off with:

f(s) = '*' in s ? reduce(vcat, (f.(s) for s in replace.(s, "*" .=> 'a':'z', count=1))) : [s]
1 Like