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
Copy file name to clipboardExpand all lines: docs/src/markdown/fnmatch.md
+54-42Lines changed: 54 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,10 @@ It is mainly used for matching filenames with glob patterns. For path names, Wil
11
11
[`globmatch`](./glob.md#globmatch) is a more appropriate choice. Not all of the features listed below are enabled by
12
12
default. See [flags](#flags) for more information.
13
13
14
-
!!! tip "Backslashes"
15
-
When using backslashes, it is helpful to use raw strings. In a raw string, a single backslash is used to escape a
16
-
character `#!py3 r'\?'`. If you want to represent a literal backslash, you must use two: `#!py3 r'some\\path'`.
14
+
/// tip | Backslashes
15
+
When using backslashes, it is helpful to use raw strings. In a raw string, a single backslash is used to escape a
16
+
character `#!py3 r'\?'`. If you want to represent a literal backslash, you must use two: `#!py3 r'some\\path'`.
17
+
///
17
18
18
19
Pattern | Meaning
19
20
----------------- | -------
@@ -31,11 +32,11 @@ Pattern | Meaning
31
32
`!(pattern_list)` | The pattern matches if the input string cannot be matched with any of the patterns in the `pattern_list`. Requires the [`EXTMATCH`](#extmatch) flag.
32
33
`{}` | Bash style brace expansions. This is applied to patterns before anything else. Requires the [`BRACE`](#brace) flag.
33
34
34
-
- Slashes are generally treated as normal characters, but on windows they are normalized. On Windows, `/` will match
35
-
both `/` and `\\`. There is no need to explicitly use `\\` in patterns on Windows, but if you do, they must be escaped
36
-
to specify a literal `\\`. If a backslash is escaped, it will match all valid windows separators, just like `/` does.
37
-
- By default, `.` is *not* matched by `*`, `?`, and `[]`. See the [`DOTMATCH`](#dotmatch) flag to match `.` at
38
-
the start of a filename without a literal `.`.
35
+
-Slashes are generally treated as normal characters, but on windows they are normalized. On Windows, `/` will match
36
+
both `/` and `\\`. There is no need to explicitly use `\\` in patterns on Windows, but if you do, they must be escaped
37
+
to specify a literal `\\`. If a backslash is escaped, it will match all valid windows separators, just like `/` does.
38
+
-By default, `.` is *not* matched by `*`, `?`, and `[]`. See the [`DOTMATCH`](#dotmatch) flag to match `.` at
39
+
the start of a filename without a literal `.`.
39
40
40
41
--8<-- "posix.md"
41
42
@@ -46,8 +47,9 @@ Many of the API functions allow passing in multiple patterns or using either [`B
46
47
you can raise or lower this limit via the keyword option `limit`. If you set `limit` to `0`, there will
47
48
be no limit.
48
49
49
-
!!! new "New 6.0"
50
-
The imposed pattern limit and corresponding `limit` option was introduced in 6.0.
50
+
/// new | New 6.0
51
+
The imposed pattern limit and corresponding `limit` option was introduced in 6.0.
52
+
///
51
53
52
54
## API
53
55
@@ -116,11 +118,13 @@ False
116
118
True
117
119
```
118
120
119
-
!!! new "New 6.0"
120
-
`limit` was added in 6.0.
121
+
/// new | New 6.0
122
+
`limit` was added in 6.0.
123
+
///
121
124
122
-
!!! new "New 8.4"
123
-
`exclude` parameter was added.
125
+
/// new | New 8.4
126
+
`exclude` parameter was added.
127
+
///
124
128
125
129
#### `fnmatch.filter` {: #filter}
126
130
@@ -139,11 +143,13 @@ pattern or a list of patterns.It returns a list of all files that matched the pa
139
143
['a.txt', 'b.txt']
140
144
```
141
145
142
-
!!! new "New 6.0"
143
-
`limit` was added in 6.0.
146
+
/// new | New 6.0
147
+
`limit` was added in 6.0.
148
+
///
144
149
145
-
!!! new "New 8.4"
146
-
`exclude` parameter was added.
150
+
/// new | New 8.4
151
+
`exclude` parameter was added.
152
+
///
147
153
148
154
#### `fnmatch.translate` {: #translate}
149
155
@@ -179,14 +185,17 @@ we wrap the entire group to be captured: `#!py3 '+(a)'` --> `#!py3 r'((a)+)'`.
179
185
('file', '33', '.test.txt')
180
186
```
181
187
182
-
!!! new "New 6.0"
183
-
`limit` was added in 6.0.
188
+
/// new | New 6.0
189
+
`limit` was added in 6.0.
190
+
///
184
191
185
-
!!! new "New 7.1"
186
-
Translate patterns now provide capturing groups for [`EXTMATCH`](#extmatch) groups.
192
+
/// new | New 7.1
193
+
Translate patterns now provide capturing groups for [`EXTMATCH`](#extmatch) groups.
194
+
///
187
195
188
-
!!! new "New 8.4"
189
-
`exclude` parameter was added.
196
+
/// new | New 8.4
197
+
`exclude` parameter was added.
198
+
///
190
199
191
200
#### `fnmatch.escape` {: #escape}
192
201
@@ -205,8 +214,9 @@ backslashes, regardless of what feature is or is not enabled. It is meant to esc
205
214
True
206
215
```
207
216
208
-
!!! new "New 8.1"
209
-
An `escape` variant for `fnmatch` was made available in 8.1.
217
+
/// new | New 8.1
218
+
An `escape` variant for `fnmatch` was made available in 8.1.
219
+
///
210
220
211
221
### `fnmatch.is_magic` {: #is_magic}
212
222
@@ -241,8 +251,9 @@ Default | `?*[]\`
241
251
[`MINUSNEGATE`](#minusnegate) | `-`
242
252
[`SPLIT`](#split) | `|`
243
253
244
-
!!! new "New 8.1"
245
-
Added `is_magic` in 8.1.
254
+
/// new | New 8.1
255
+
Added `is_magic` in 8.1.
256
+
///
246
257
247
258
## Flags
248
259
@@ -299,11 +310,11 @@ other character. Dots will not be matched in `[]`, `*`, or `?`.
299
310
`EXTMATCH` enables extended pattern matching. This includes special pattern lists such as `+(...)`, `*(...)`, `?(...)`,
300
311
etc. See the [syntax overview](#syntax) for more information.
301
312
302
-
!!! tip "EXTMATCH and NEGATE"
303
-
304
-
When using `EXTMATCH` and [`NEGATE`](#negate) together, if a pattern starts with `!(`, the pattern will not
305
-
be treated as a [`NEGATE`](#negate) pattern (even if `!(` doesn't yield a valid `EXTMATCH` pattern). To
306
-
negate a pattern that starts with a literal `(`, you must escape the bracket: `!\(`.
313
+
/// tip | EXTMATCH and NEGATE
314
+
When using `EXTMATCH` and [`NEGATE`](#negate) together, if a pattern starts with `!(`, the pattern will not
315
+
be treated as a [`NEGATE`](#negate) pattern (even if`!(` doesn't yield a valid `EXTMATCH` pattern). To
316
+
negate a pattern that starts with a literal `(`, you must escape the bracket: `!\(`.
317
+
///
307
318
308
319
#### `fnmatch.BRACE, fnmatch.B` {: #brace}
309
320
@@ -314,20 +325,21 @@ Redundant, identical patterns are discarded[^1] by default.
314
325
For simple patterns, it may make more sense to use [`EXTMATCH`](#extmatch) which will only generate a single
315
326
pattern which will perform much better: `@(ab|ac|ad)`.
316
327
317
-
!!! warning "Massive Expansion Risk"
318
-
1. It is important to note that each pattern is matched separately, so patterns such as `{1..100}` would generate
328
+
/// warning | Massive Expansion Risk
329
+
1. It is important to note that each pattern is matched separately, so patterns such as `{1..100}` would generate
319
330
**one hundred** patterns. Sometimes patterns like this are needed, so construct patterns thoughtfully and carefully.
320
331
321
-
2. `BRACE` and [`SPLIT`](#split) both expand patterns into multiple patterns. Using these two syntaxes
332
+
2.`BRACE` and [`SPLIT`](#split) both expand patterns into multiple patterns. Using these two syntaxes
322
333
simultaneously can exponential increase in duplicate patterns:
0 commit comments