|
| 1 | +# Wildcards and Pattern Matching |
| 2 | + |
| 3 | +This plugin stores its configuration in YAML frontmatter. The value of |
| 4 | +`sorting-spec: |` is a multi-line string containing the plugin's sorting |
| 5 | +specification "language" (the plugin docs call it an informal language / syntax). |
| 6 | + |
| 7 | +In this document we may refer to it as a DSL (Domain-Specific Language): a small |
| 8 | +purpose-built language parsed by the plugin. |
| 9 | + |
| 10 | +In examples below, snippets may show only the sorting-spec lines (the content |
| 11 | +that goes under `sorting-spec: |`) for brevity. |
| 12 | + |
| 13 | +Some parts of the syntax look regex-like (for example `\d\d\d\d`), but matching |
| 14 | +is not "full regex everywhere". In particular, the `...` token is a plugin |
| 15 | +wildcard and should not be treated as the regex `.*`. |
| 16 | + |
| 17 | +## The `...` wildcard |
| 18 | + |
| 19 | +`...` is used for prefix/suffix matching and for patterns where you want to |
| 20 | +match an arbitrary run of characters. |
| 21 | + |
| 22 | +Examples: |
| 23 | + |
| 24 | +- `Focus...` matches names starting with `Focus`. |
| 25 | +- `...ive` matches names ending with `ive`. |
| 26 | +- `A...s` matches names starting with `A` and ending with `s`. |
| 27 | + |
| 28 | +Practical rules: |
| 29 | + |
| 30 | +- Any characters you place next to `...` (including spaces) are literal and must |
| 31 | + exist in the name. |
| 32 | +- If you want to match an exact name shape that ends where your pattern ends, |
| 33 | + omit `...`. |
| 34 | + |
| 35 | +### Example: year folders |
| 36 | + |
| 37 | +Given folders: |
| 38 | + |
| 39 | +- `Reviewed in 2023` |
| 40 | +- `Reviewed in 2024` |
| 41 | +- `Reviewed in 2025` |
| 42 | +- `Reviewed in 2026` |
| 43 | + |
| 44 | +To match them exactly as a group, prefer: |
| 45 | + |
| 46 | +```yaml |
| 47 | +/folders Reviewed in 20\d\d |
| 48 | + > a-z |
| 49 | +``` |
| 50 | + |
| 51 | +If you write: |
| 52 | + |
| 53 | +```yaml |
| 54 | +/folders Reviewed in 20\d\d ... |
| 55 | + > a-z |
| 56 | +``` |
| 57 | + |
| 58 | +note the space before `...`. That space is a literal character, so this pattern |
| 59 | +only matches names that contain a space after the year (for example `Reviewed in |
| 60 | +2026 Q1`), and it will _not_ match exact names like `Reviewed in 2026`. |
| 61 | + |
| 62 | +If you want to allow an optional suffix that starts with a space, but also match |
| 63 | +the exact name, define two groups (exact first), or use an exact match without |
| 64 | +`...`. |
| 65 | + |
| 66 | +## Digits and ISO dates |
| 67 | + |
| 68 | +Common digit patterns: |
| 69 | + |
| 70 | +- `\d` matches one digit. |
| 71 | +- `\d\d\d\d` is often used for years. |
| 72 | + |
| 73 | +ISO date prefixes (`YYYY-MM-DD`) sort correctly as plain text, so reverse |
| 74 | +alphabetical (`> a-z`) gives newest-first: |
| 75 | + |
| 76 | +```yaml |
| 77 | +/:files \d\d\d\d-\d\d-\d\d ... |
| 78 | + > a-z |
| 79 | +``` |
| 80 | + |
| 81 | +## Indentation matters |
| 82 | + |
| 83 | +In the plugin docs, the lines like `< a-z`, `> a-z`, `< modified` are referred to |
| 84 | +as sorting instructions / sorting methods (not a YAML concept). In this file we |
| 85 | +use the term "sorting instruction". |
| 86 | + |
| 87 | +A sorting instruction must be indented under the group it applies to. |
| 88 | + |
| 89 | +More precisely: inside the `sorting-spec: |` text, the sorting instruction line |
| 90 | +must start at a greater indentation level than the group line immediately above |
| 91 | +it (at least one extra space). |
| 92 | + |
| 93 | +```yaml |
| 94 | +/folders Reviewed in 20\d\d |
| 95 | + > a-z |
| 96 | +``` |
| 97 | + |
| 98 | +In contrast, this is *not* grouped correctly (same indentation as the group |
| 99 | +line): |
| 100 | + |
| 101 | +```yaml |
| 102 | +/folders Reviewed in 20\d\d |
| 103 | +> a-z |
| 104 | +``` |
| 105 | + |
| 106 | +If the sorting instruction is not indented more than the group line, the plugin |
| 107 | +will not associate it with that group. |
| 108 | + |
| 109 | +## Complete example (folders first, then files) |
| 110 | + |
| 111 | +Full YAML frontmatter form: |
| 112 | + |
| 113 | +```yaml |
| 114 | +--- |
| 115 | +sorting-spec: | |
| 116 | + target-folder: 03 Literature review |
| 117 | + /folders Reviewed in 20\d\d |
| 118 | + > a-z |
| 119 | + /folders |
| 120 | + < a-z |
| 121 | + /:files |
| 122 | + < a-z |
| 123 | +--- |
| 124 | +``` |
0 commit comments