declarativeNetRequest regexFilter

262 views
Skip to first unread message

Browser Extenstion

unread,
Nov 4, 2023, 4:26:59 PM11/4/23
to Chromium Extensions
I want to create a regular expression that will match all subdomains except admin.example.com.

So, the regex is:
^(https?:\/\/)?((?!admin\.example\.com).)*example\.com

It works as expected.

Now I want to convert the regex to use in regexFilter:
^(https?://)?((?!admin\\.example\\.com).)*example\\.com

If I insert this expression, I get an error.
In this regard, my question is: does declarativeNetRequest support such a regex?
How should I modify the expression?

wOxxOm

unread,
Nov 5, 2023, 4:30:30 AM11/5/23
to Chromium Extensions, Browser Extenstion
The API uses RE2 syntax, so no, negative lookahead/lookbehind is not supported.

wOxxOm

unread,
Nov 5, 2023, 4:32:05 AM11/5/23
to Chromium Extensions, wOxxOm, Browser Extenstion
Try adding another rule for the admin domain with a bigger "id" and "type":"allow" or "allowAllRequests"

Browser Extenstion

unread,
Nov 5, 2023, 6:23:17 AM11/5/23
to Chromium Extensions, wOxxOm, Browser Extenstion
>>> Try adding another rule for the admin domain with a bigger "id" and "type":"allow" or "allowAllRequests"

Thanks! Works!
Reply all
Reply to author
Forward
0 new messages