1

I'm trying to block the annoying youtube ads with pihole but unfortunately it doesn't work for me. The following is not viewed at all:

(rr[\d]{1}---[\s]{2}-[\s]{8}-[\w]{4})\.googlevideo\.com

Has anyone had similar experiences?

Examples look like this

rr1---sn-8xgn5uxa-quhl.googlevideo.com
rr1---sn-8xgn5uxa-quhl.googlevideo.com
rr3---sn-8xgn5uxa-quhz.googlevideo.com
rr6---sn-8xgn5uxa-quhl.googlevideo.com
allstar_141
  • 43
  • 1
  • 1
  • 8
  • 1
    Do you have some examples that it should and should not match? – The fourth bird Mar 28 '22 at 15:18
  • What are the rules, in English, for what should match? – Andy Lester Mar 28 '22 at 15:19
  • @Thefourthbird if an advertisement is played the following is displayed in the query log (examples only): rr1---sn-8xgn5uxa-quhl.googlevideo.com or rr1---sn-8xgn5uxa-quhl.googlevideo.com or rr3---sn-8xgn5uxa-quhz.googlevideo.com or rr6---sn-8xgn5uxa-quhl.googlevideo.com I try to block this using the regex – allstar_141 Mar 28 '22 at 15:21
  • @allstar_141 Can you add those examples to the question? I think this pattern will match those examples `rr\d---sn-[a-z0-9]{8}-\w{4}\.googlevideo\.com` https://regex101.com/r/RfGRId/1 – The fourth bird Mar 28 '22 at 15:21
  • @Thefourthbird I have added the examples on regex101.com everything works without no problems only in pihole unfortunately not – allstar_141 Mar 28 '22 at 15:25
  • @allstar_141 Try it like this `rr[[:digit:]]---sn-[[:alnum:]]{8}-[[:alnum:]]{4}\.googlevideo\.com` https://regex101.com/r/5sCtKz/1 – The fourth bird Mar 28 '22 at 15:26
  • `\s` is a meta-escape for whitespace, not literal "s". – MonkeyZeus Mar 28 '22 at 15:28
  • @Thefourthbird I'll try that and get right back to you. Thanks already – allstar_141 Mar 28 '22 at 15:28

3 Answers3

2

Using [\s]{2} in the pattern (which can be written as \s{2} matches 2 whitespace chars, but in the example data there is sn

The single meta characters in this case do not have to be placed between square brackets.

Looking at some documentation on this page \w \s and \d are not supported.

You might use

rr[[:digit:]]---sn-[[:alnum:]]{8}-[[:alnum:]]{4}\.googlevideo\.com

The pattern matches:

  • rr[[:digit:]] Match rr and a single digit
  • ---sn- Match literally
  • [[:alnum:]]{8} Match 8 alphanumerics
  • -[[:alnum:]]{4} Match - and 4 alphanumerics
  • \.googlevideo\.com Match .googlevideo.com

See a regex demo.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

This pattern matches all your samples but it may be too tight?

rr\d---sn-8xgn5uxa-quh\w.googlevideo.com
0

Pi-Hole documentation does not mention the usual abbrevations for character classes (like \d, \s or \w you used).

If you replace your character classes with the ones from the Pi-Hole documentation you end with

(rr[:digit:]{1}---[:space:]{2}-[:space:]{8}-[A-Za-z0-9_]{4})\.googlevideo\.com

Probably the \s is not what you originally wanted, as your examples contain letters there instead of spaces. And \w includes an underscore, that does not appear in your examples. Also a {1} can be skipped.

So I would suggest this expression:

(rr[:digit:]---[:alnum:]{2}-[:alnum:]{8}-[:alnum:]{4})\.googlevideo\.com

If you don't need the hostname-part for further processing, you could remove the group marker () around it.

cyberbrain
  • 3,433
  • 1
  • 12
  • 22