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

**URL:** <https://discourse.julialang.org/t/generating-all-string-possibilities-with-wildcard-characters-code-golf-based/85209>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 2, 2022, 11:48pm UTC](https://discourse.julialang.org/t/generating-all-string-possibilities-with-wildcard-characters-code-golf-based/85209 "2022-08-02T23:48:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mostol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostol/32/33829_2.png) [@mostol](https://discourse.julialang.org/u/mostol)\
**Post date:** [August 2, 2022, 11:48pm UTC](https://discourse.julialang.org/t/generating-all-string-possibilities-with-wildcard-characters-code-golf-based/85209/1 "2022-08-02T23:48:49Z")

</div>

I ran into [this code golf problem](https://codegolf.stackexchange.com/questions/250522/generate-all-possibilities-of-words) 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:
> 
> ```julia
> *e*c*m*
> 
> ```
> 
> Output:
> 
> ```julia
> aeacama
> aeacamb
> ...
> ...
> ...
> welcome
> ...
> ...
> zezczmz
> 
> ```

After working through some initial attempts, I realized I actually have no idea how I would solve this effectively! 😅 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](https://codegolf.stackexchange.com/a/250527) 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?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [August 3, 2022, 12:22am UTC](https://discourse.julialang.org/t/generating-all-string-possibilities-with-wildcard-characters-code-golf-based/85209/2 "2022-08-03T00:22:11Z")

</div>

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

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

```
