Regex filter on domain & sub-domain, am i doing it right?

I am try to whitelist this domain and sub-domain(not sure if i am using the correct term) using Regex, am i doing it right?

example of domain & sub-domains:

https://gameserver.com
login.gameserver.com
download.gameserver.com
s1.gameserver.com

(https://)?([a-z0-9]+[.])*gameserver[.]com

Your first example domain is actually a URL. The https part is the scheme used to connect to the following domain, Pi-hole will never see this part.

You also don't need to match the entire domain. Just matching a substring will work.

Thirdly, to match a literal dot (.) you need to escape it (\.), since the dot itself is used as a wildcard that matches any character.

You can simplify your regex to

(^|\.)gameserver\.com$

^ and $ match the start and end if a line. That ensures you do not match nefarious domains like xxxgameserver.comyyy, but do match subdomains like zzz.gameserver.com (notice the dot after the subdomain).

2 Likes

is there a different between your and this?
still quite confuse on this regex

( \ .|^)gameserver.com$ * ignore spacing

(^|\.)gameserver\.com$
and
(\.|^)gameserver.com$

Those are functionally the same. The first section inside the ()s is an OR statement. Either the word gameserver is at the start of the domain or is immediately preceeded by a dot. The order doesn't matter. You could also escape the dot before com.

(To mark text as code you can use the Preformatted Text button or code fences with backticks ` around the code to mark as formatted.)

could this code also block these:
i believe it could?

s1.download.gameserver.com
m00.s3.status.gameser.com
hype.epic.mms.login.pub.gameserver.com

Test your regex at regex101.com. It has a good interface that will check your regex for validity and show if it does or does not match a domain and why.

You may also want to visit our regex tutorial:

https://docs.pi-hole.net/regex/tutorial/

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.