Well, this is a challenging one!
A
proper solution would likely involve parsing the lines and storing each part separately into arrays, which would be re-built into the desired output, or something like that. It would take some time to figure out.
I do have a quick hack solution, but I don't particularly recommend it.
Code:
text='/(ar|az|dua|en|fa|fr)/administrator/(index|index2).php'
text="$( echo "$text" | tr '()|' '{},' )"
eval printf '%s\\n' "$text"
This translates the line into a valid
brace expansion. Unfortunately though the final printing involves using
eval to expand it, and
eval has worrisome
security issues. I generally suggest avoiding it unless there's no other choice. It may be safe enough here though, as long as the input text is known and trustworthy.
It also won't work correctly if any part of the original line contains whitespace, or if there happen to be '()|' characters that aren't part of the expansion pattern.
(Incidentally, I tried to use
parameter substitutions instead of
tr, but there seems to be a bug in my bash that keeps the substitution to "}" from being handled correctly.)