Mine looks pretty similar:
^.*\.?(facebook|.*fb.*?)\..+$
Your opening match clause ^(.+\.)??
seems to be more efficient than both my approach ^.*\.?
and the one Pi-hole inserts for wildcard entries (^|\.)
- more efficient in the sense that regex101.com
shows some 8 or 38 steps less needed to evaluate yours (using other-sub.graph.fb.com
as test string).
Of course, that's no hard assessment criterion, as Pi-hole's runtime behaviour might differ, depending on the actually regex implementation used.
Midways, mine would still match fbcdn
or tfbnw
parts, as I apply the leading and trailing wildcard matches in the domain part that you cut away from yours.
Towards EOL, mine would also catch country specific TLDs like .co.uk
or .nl
, but may overblock, e.g. by also matching facebook.someblacklistingdomain.com
.
I am going to adopt your opening match to my regex.
And just out of curiosity, maybe a developer could comment whether it actually would be beneficial to replace (^|\.)
by ^(.+\.)??
in simple wildcard matching - absolutely no priority though