The Purge method will work only for the specific url that is being requested. It is not possible to use regular expressions with Purge.
For example: a request for www.example.com/uri is made and a Purge is called, only the object for this whole URL will be removed from cache. Then, if you want to use Purge you will have to implement the following feature on your VCL:
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
...
# allow PURGE from localhost and 192.168.55...
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}
...
}
After that, all you need to do to purge an URL is to send a request with the Purge method to your Varnish like this:
$ curl -X PURGE "www.example.com/desired/uri"
The Ban is used when you want to remove many objects with only one request.This can be accomplished using regular expressions that are not available in Purge. In order to use it you should have a code similar to the one below, maintaining the acl from before:
sub vcl_recv {
...
if (req.method == "BAN") {
# Same ACL check as above:
if (!client.ip ~ purge) {
return(synth(403, "Not allowed."));
}
ban("req.http.host == " + req.http.host +
" && req.url ~ " + req.url);
# Throw a synthetic page so the
# request won't go to the backend.
return(synth(200, "Ban added"));
}
...
}
To ban objects is similar to purge but now you can send Regex. The example below shows how to ban all png files from the host www.example.com:
$ curl -X BAN "www.example.com/.png$"
All the information was retrieved from Varnish docs.
I hope this answer can help you understand how Bans and Purges work and that you can identify how they can help you.
If anything is missing or is not addressing your needs, please edit your question to be clearer in your doubts (there is a divergence between the tittle and the question that may lead to confusion) and I'll be happy to edit the answer.