Regex with $

Adam

Filters Developer
Staff member
Moderator
How to make a regex rule which end with "$"?
For example, I want to block all request which end with .jpg
So I think this rule should works:
Code:
/\.jpg$/
but I can not add this to Adguard, because I see that, this rule is incorrect.
If I add "$," after last "/" it works.
Code:
/\.jpg$/$,
 

avatar

Administrator
Staff member
Administrator
You should escape $ character. Also, you may need to add multiline modifier (m) to the regular expression.

Something like this:
Code:
||example.org^$replace=/<head>\$/HELLO<head>/m
 

Adam

Filters Developer
Staff member
Moderator
Thank you for your answer.
I think, I should add more details, because probably you didn't understand what I mean or maybe I do not understand what you mean :)

I do not want use a replace rule, I want use regex - https://adguard.com/en/filterrules.html#regexp-support
and I want to block request which end with .jpg
In this case I want use $ as a special character - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-dollar
For example on this website - http://konsoleigry.pl/

I want add this rule:
Code:
/(.jpg)$/
but I can not add this to Adguard.
I must add "$," after "/":
Code:
/(.jpg)$/$,
and it works as I expect.

upload_2017-1-2_14-14-26.png

I wonder why I must add "$,"?
 
Top