Filter some Apache Conf to extract all ServerName and ServerAlias, then output them one per line
What is "bad match" in here?


RemoveBadMatch="s/^\s*($GrepAndFilter)\s+//gI"



My understanding is that this pattern is used to remove the $GrepAndFilter prefix from lines, with any surrounding whitespace. I don't see that prefix as "bad match" in any sense of the word. It seems RemoveFilterPrefix would be a better fit.



Here, instead of \s*$ as the pattern, I'd use \s+$,
to emphasize that the content will be modified only when there are non-zero trailing whitespaces.


RemoveTrailingWhitespaces="s/\s*$//"





Here, the pattern doesn't match the name:


ReplaceSpacesWithNewLines="s/ +/\s/g"



I think you meant \n as the replacement,
because \s doesn't have a special meaning in a replacement string,
so as written,
this command will replace spaces with the letter s.



grep assumes /dev/stdin as input by default, no need to specify it explicitly.



In many systems, the Apache configuration files often contain ServerName and ServerAlias on commented out lines.
The posted script won't work with such lines,
and I can easily imagine such lines in production systems too.
I suggest to make the script more robust by excluding commented lines.
This could be as simple as making the first filter more strict:

GrepAndFilter="^\s*(ServerName|ServerAlias)\s+"