I would like to write a script that takes one argument that might look like this:
abc(ag)de*
a, b, c are literal characters.
(ag) means ‘an ‘a’ or a ‘g”.
* means any one letter or number.
I want the script to create an Array of all the possible strings the input could represent. (The purpose is to check if they’re available domain names.)
The input could also be something like abc(ag)de(mnlop) where there are more than on character class.
Seems like the first task is to split it into an Array or Arrays, so the first example would be…
[ ['a'], ['b'], ['c'], ['a', 'g'], ['d'], ['e'], [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', # etc... ] ]
This is where I get stuck. I don’t know how to split it up into pieces like that.
Any suggestions on how to approach it?
Here’s a pretty compact solution. It’s in no way optimized for performance which puts some constraints on the patterns you supply e.g. too many wildcards is probably not the best idea.
Here’s the code
The output from running the code above is (slightly edited):
Please feel free to ask if you have any questions about the code above.