Should dot be escaped in declarativeNetRequest regexFilter?

73 views
Skip to first unread message

Vaibhav Nigam

unread,
Oct 25, 2022, 4:10:11 AM10/25/22
to Chromium Extensions
Hi,
Documentation for RuleCondition in declarativeNetRequest API says:

regexFilter can be used as "Regular expression to match against the network request url. This follows the RE2 syntax".

As per RE2 syntax, dot '.' is not a metacharacter and can match itself.

But in examples on Chrome docs page, dot has been escaped in regexFilter.
{
"id": 7,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "https://\\1.xyz.com/"
}
},
"condition": {
"regexFilter": "^https://www\\.(abc|def)\\.xyz\\.com/",
"resourceTypes": [
"main_frame"
]
}
},

Is there an exhaustive list of special characters to be escaped in regexFilter?

Thanks,
Vaibhav Nigam

wOxxOm

unread,
Oct 25, 2022, 10:50:30 AM10/25/22
to Chromium Extensions, laz...@gmail.com
In regexFilter dots must be escaped and the RE2 documentation you've linked says as much i.e. dot matches "any character".
In regexSubstitution dot is a plain character so it must not be escaped.

Vaibhav Nigam

unread,
Oct 26, 2022, 6:13:14 AM10/26/22
to Chromium Extensions, wOxxOm, Vaibhav Nigam
Thanks @wOxxOm. That makes it clear.
Reply all
Reply to author
Forward
0 new messages