Improve Regex highlighting (#28183)

| Zed 0.180.2 | With this PR |
| --- | --- |
|
![Image](https://github.com/user-attachments/assets/e840bd81-25ff-4c7a-af03-bac6db11f910)
|
![Image](https://github.com/user-attachments/assets/3fd58164-8992-44e1-be01-8c6d70f9587d)
|

```js
match = "424242"
regex = /(42)+?\d{2}\1/g
```

- `/`: `operator` -> `string.regex` (like `"` for regex strings)
- `+?`: `operator.regex`
- `\d`: `string.escape` -> `string.escape.regex`
- `\1`: `keyword.operator.regex` (backreference)
- `/g`: `keyword.regex` -> `keyword.operator.regex`
- `{2}`: `number` -> `number.quantifier.regex`

Release Notes:

  - Improved Regex highlighting
This commit is contained in:
chbk 2025-04-18 18:44:13 +02:00 committed by GitHub
parent 7badd6053d
commit f97546b6ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 5 deletions

View file

@ -85,7 +85,7 @@
(escape_sequence) @string.escape
(regex) @string.regex
(regex_flags) @keyword.regex
(regex_flags) @keyword.operator.regex
(number) @number
; Tokens
@ -145,6 +145,8 @@
"??="
] @operator
(regex "/" @string.regex)
[
"("
")"