Skip to content

Conversation

SelYui
Copy link

@SelYui SelYui commented Jun 26, 2025

This PR updates the $app modifier documentation to include support for regular expressions
AdguardTeam/CoreLibs#1906

Add support for regular expressions in `$app` modifier
@SelYui SelYui requested review from sfionov and slavaleleka June 26, 2025 14:04
updated based on comments
@SelYui SelYui marked this pull request as ready for review August 11, 2025 09:39
Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 To request another review, post a new comment with "/windsurf-review".

@@ -1939,7 +1967,7 @@ In AdGuard for Windows, Mac and Android with [CoreLibs] v1.11 or later, JSONPath
{
"elems": [
{
"a": {"b": {"c": 123}},
"a": {"b": {"c": 123}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma at the end of line 1970 was removed, but this would make the JSON example invalid. JSON requires commas between array/object elements.

You can use regular expressions in the `$app` modifier by enclosing them in forward slashes `/.../`. This allows for more flexible matching — for example, targeting a group of apps from the same publisher or matching complex patterns.

- `||baddomain.com^$app=/org\.example\.[a-z0-9_]+/` — applies to all apps whose package name starts with `org.example` (e.g. `org.example.app1`, `org.example.utility`, etc.).
- `||baddomain.com^$app=/^org\.example\.app\$\|^org\.example\.[ab].*/` — applies to `org.example.app` and to any app whose package starts with `org.example.a` or `org.example.b`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regular expression example is quite complex with double escaping. Consider adding a simpler example first before showing this more advanced pattern, or adding a comment explaining the escaping requirements (e.g., why \. is needed instead of just .).

@@ -425,6 +425,19 @@ This modifier lets you narrow the rule coverage down to a specific application (

For Mac, you can find out the bundle ID or the process name of the app by viewing the respective request details in the Filtering log.

**Syntax**

The modifier is a list of one or more expressions separated by the `|` symbol, each of which is matched against a application in a particular way depending on its type (see below).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The modifier is a list of one or more expressions separated by the `|` symbol, each of which is matched against a application in a particular way depending on its type (see below).
The modifier is a list of one or more expressions, each of which is matched against an application in a particular way depending on its type. These expressions are separated by the `|` symbol.

entry_i = ( regular_app / wildcard_app / regexp )
```

- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically.
- **`regular_app`** — a regular application name (`example.app`). It corresponds to the specified application and its subapplications and is matched lexicographically.


- **`regular_app`** — a regular application name (`example.app`). Corresponds the specified application and its subapplications. It is matched lexicographically.
- **`wildcard_app`** — an application name ending with a wildcard character `*`, such as `org.example.*` or `com.ad*`. It matches all applications whose names start with the specified prefix. Matching is done lexicographically.
- **`regexp`** — a regular expression, starts and ends with `/`. The pattern works the same way as in the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **`regexp`** — a regular expression, starts and ends with `/`. The pattern works the same way as in the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`.
- **`regexp`** — a regular expression that starts and ends with `/`. It works the same way as the basic URL rules, but the characters `/`, `$`, `,`, and `|` must be escaped with `\`.

@@ -435,17 +448,32 @@ If you want the rule not to be applied to certain apps, start the app name with
- `||baddomain.com^$app=~org.example.app` — a rule to block requests that match the specified mask and are sent from any app except for the `org.example.app`.
- `||baddomain.com^$app=~org.example.app1|~org.example.app2` — same as above, but now two apps are excluded: `org.example.app1` and `org.example.app2`.

You can use wildcards in the $app modifier:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can use wildcards in the $app modifier:
You can use wildcards in the `$app` modifier:


The `$app` modifier supports combining all three types of entries — plain names, wildcards, and regular expressions — within the same rule, but it does not allow combining negated and non-negated expressions together.

- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and all matching `org.example.[a-z]+` apps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and all matching `org.example.[a-z]+` apps.
- `||example.com^$app=org.example.app|org.example.*|/org\.example\.[a-z]+/` — applies to `org.example.app`, all matching `org.example.*` and `org.example.[a-z]+` apps.

Apps in the modifier value cannot have a wildcard, e.g. `$app=com.*.music`.
Rules with such modifier are considered invalid.
- Apps in the modifier value cannot include a wildcard inside the string , e.g. `$app=com.*.music`.
Use a regular expression instead: `$app=/com\..*\.music/`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use a regular expression instead: `$app=/com\..*\.music/`
Use a regular expression instead: `$app=/com\..*\.music/`.

@el-termikael el-termikael requested a review from sfionov August 12, 2025 15:59

:::

:::info Compatibility

- Only AdGuard for Windows, Mac, Android are technically capable of using rules with `$app` modifier.
- On Windows the process name is case-insensitive starting with AdGuard for Windows with [CoreLibs] v1.12 or later.
- Support for regular expressions and combined formats in `$app` is available starting from CoreLibs v1.19 or later.
Copy link
Contributor

@slvvko slvvko Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does combined formats mean? it cannot be searched on the page. i.e. it looks like you are introducing a new term here

@slvvko slvvko removed the request for review from slavaleleka August 13, 2025 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants