You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9eeff3b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/src/extend/selectors.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ The following selectors are supported:
33
33
- wildcard (matches all nodes): `*`
34
34
- attribute existence: `[attr]`
35
35
- attribute value: `[attr="foo"]` or `[attr=123]`
36
-
- attribute regex: `[attr=/foo.*/]` <sub>(with some [known issues](#known-issues))</sub>
36
+
- attribute regex: `[attr=/foo.*/]`
37
37
- attribute conditions: `[attr!="foo"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`
38
38
- nested attribute: `[attr.level2="foo"]`
39
39
- field: `FunctionDeclaration > Identifier.id`
@@ -147,21 +147,25 @@ Or you can enforce that calls to `setTimeout` always have two arguments:
147
147
148
148
Using selectors in the `no-restricted-syntax` rule can give you a lot of control over problematic patterns in your codebase, without needing to write custom rules to detect each pattern.
149
149
150
-
### Known issues
150
+
### Using regular expressions
151
151
152
-
Due to a [bug](https://github.com/estools/esquery/issues/68) in [esquery](https://github.com/estools/esquery), regular expressions that contain a forward-slash character `/` aren't properly parsed, so `[value=/some\/path/]` will be a syntax error. As a [workaround](https://github.com/estools/esquery/issues/68), you can replace the `/` character with its unicode counterpart, like so: `[value=/some\u002Fpath/]`.
152
+
You can use regular expressions in attribute selectors. For example, the following selector matches all `Identifier` nodes with a `name` value that starts with "foo":
153
153
154
-
For example, the following configuration disallows importing from `some/path`:
154
+
```text
155
+
Identifier[name=/^foo/]
156
+
```
157
+
158
+
You can also use forward slashes in your regular expressions. For example, the following configuration disallows importing from `some/path`:
Note that the `\` character needs to be escaped (`\\`) in JSON and string literals.
171
+
Note that the `/` character inside the regular expression needs to be escaped (`\/`) so it is not interpreted as the end of the regular expression. Additionally, because the selector is inside a JSON string, the backslash character itself needs to be escaped (`\\`).
0 commit comments