Purge every package with a given string in its name
A quick troll through the Aptitude Reference Manual on patterns I found this entry.
Working from that, aptitude purge ?name('apache2')
will do what you want, but if you're wise you'll run it with -s
the first time so you can see what all it'll remove before committing to the task.
I would parse the output of dpkg --get-selections, doing something along the following.
$ dpkg --get-selections | cut -f 1 | grep apache | sudo xargs aptitude purge -y
(For better understanding, feel free to try the pipe out one step at a time.)