Skip to content

Commit e31262d

Browse files
committed
Minor tweaks
Standardize on "number signs" for mentions of `#` (though a couple of them read better as just the character). Also change the multi-line example to not include a `/` at the start, which matches the single-line version.
1 parent c045e21 commit e31262d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Documentation/Evolution/DelimiterSyntax.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ This allows the captures to be referenced as `match.identifier` and `match.hex`,
8787

8888
### Extended delimiters `#/.../#`, `##/.../##`
8989

90-
Backslashes may be used to write forward slashes within the regex literal, e.g `/foo\/bar/`. However, this can be quite syntactically noisy and confusing. To avoid this, a regex literal may be surrounded by an arbitrary number of balanced octothorpes. This changes the delimiter of the literal, and therefore allows the use of forward slashes without escaping. For example:
90+
Backslashes may be used to write forward slashes within the regex literal, e.g `/foo\/bar/`. However, this can be quite syntactically noisy and confusing. To avoid this, a regex literal may be surrounded by an arbitrary number of balanced number signs. This changes the delimiter of the literal, and therefore allows the use of forward slashes without escaping. For example:
9191

9292
```swift
9393
let regex = #/usr/lib/modules/([^/]+)/vmlinuz/#
9494
// regex: Regex<(Substring, Substring)>
9595
```
9696

97-
The number of pounds may be further increased to allow the use of e.g `/#` within the literal. This is similar in style to the raw string literal syntax introduced by [SE-0200], however it has a couple of key differences. Backslashes do not become literal characters. Additionally, a multi-line mode, where whitespace and line-ending comments are ignored, is entered when the opening delimiter is followed by a newline.
97+
The number of `#` characters may be further increased to allow the use of e.g `/#` within the literal. This is similar in style to the raw string literal syntax introduced by [SE-0200], however it has a couple of key differences. Backslashes do not become literal characters. Additionally, a multi-line mode, where whitespace and line-ending comments are ignored, is entered when the opening delimiter is followed by a newline.
9898

9999
```swift
100100
let regex = #/
101-
/usr/lib/modules/ # Prefix
101+
usr/lib/modules/ # Prefix
102102
(?<subpath> [^/]+)
103103
/vmlinuz # The kernel
104104
#/
@@ -143,7 +143,7 @@ let regex = #/
143143

144144
In this mode, [extended regex syntax][extended-regex-syntax] `(?x)` is enabled by default. This means that whitespace becomes non-semantic, and end-of-line comments are supported with `# comment` syntax.
145145

146-
This mode is supported with any (non-zero) number of pound characters in the delimiter. Similar to multi-line strings introduced by [SE-0168], the closing delimiter must appear on a new line. To avoid parsing confusion, such a literal will not be parsed if a closing delimiter is not present. This avoids inadvertently treating the rest of the file as regex if you only type the opening.
146+
This mode is supported with any (non-zero) number of `#` characters in the delimiter. Similar to multi-line strings introduced by [SE-0168], the closing delimiter must appear on a new line. To avoid parsing confusion, such a literal will not be parsed if a closing delimiter is not present. This avoids inadvertently treating the rest of the file as regex if you only type the opening.
147147

148148
### Ambiguities with comment syntax
149149

0 commit comments

Comments
 (0)