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
docs: Finish docs and tests for regex searches (#1051)
* docs,test: Add examples of searching for time stamps
* test: Add tests to show the text that is searched by description
* docs: Document how description's search text is constructed.
* test: Search description for short tags, excluding sub-tags
It's more complicated than I expected!
Roll on regex searching of tags
* test: Search description for sub-tags
* test: Simplify regexes by using String.raw
* test: Add missing 'it' block, for consistency
* test: More useful example for sub-tag search
And remove irrelevant comment
* docs: Document searching short tags and sub-tags
Roll on regex searching in tag and tags instructions.
* docs: Be consistent with case-insensitive flag
* docs: Heading regex searches are also case-sensitive
by default
* docs: Add a regex demo to examples.md
* test: Use String.raw for all regex searches
This makes it more likely that anyone added a future test
that requires an escape character will use this form,
instead of using the less readable '\\'.
* docs: Explain what [...] means
* docs: Add 'Escaping special characters' section
* docs,vault: Link between regex docs and sample page
The links won't work until both this PR is merged,
and the next release is done.
* docs: Improve the 'Important links' section
* docs: Link to tickets in 'known limitations' section
* test: Add regex demo of an example used for Boolean searches
* docs: Document pipe (|) in regex - and add example
* docs: Remove stray URL
Online tools for experimenting with - and testing - regular expressions:
124
+
101
125
-[Regex Testing Tool: regex101](https://regex101.com/): Select the flavor 'ECMAScript (JavaScript)'
126
+
127
+
Implementation details:
128
+
102
129
- Implemented using [JavaScript's RegExp implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
103
130
- Supports [JavaScript RegExp Flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags), although not all of them are relevant in this context.
104
131
@@ -109,22 +136,103 @@ Please be aware of the following limitations in Tasks' implementation of regular
109
136
- The single error message `Tasks query: cannot parse regex (description); check your leading and trailing slashes for your query` may mean any of:
110
137
- The opening or closing `/` is missing from the query.
111
138
- The regular expression is not valid, for example `description regex matches /[123/`.
139
+
- Logged in [#1038](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1038) and [#1039](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1039)
112
140
- No error when part of the pattern is lost, for example because unescaped slashes are used inside the pattern.
113
141
- For example, `path regex matches /a/b/c/d/` actually searches for `path regex matches /a/`.
114
142
- In this case, the query should be `path regex matches /a\/b\/c\/d/`.
143
+
- Logged in [#1037](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1037)
115
144
- Illegal flags are ignored.
116
145
- For example, the query `description regex matches /CASE/&` should give an error that `&` (and similar) are unrecognised flags.
117
146
- The `tag` or `tags` instruction does not yet support regular expression searches.
147
+
- Logged in [#1040](https://github.com/obsidian-tasks-group/obsidian-tasks/discussions/1040)
118
148
-[Lookahead and Lookbehind](https://www.regular-expressions.info/lookaround.html) searches are untested, and are presumed not to work on Apple mobile devices, or to cause serious performance problems with slow searches.
119
149
120
150
## Regular expression examples
121
151
122
-
Example searches:
152
+
Below are some example regex searches, to give some ideas of what can be done.
153
+
154
+
There are some more examples in the [Tasks-Demo sample vault](https://github.com/obsidian-tasks-group/obsidian-tasks/tree/main/resources/sample_vaults/Tasks-Demo), in the file [Regular Expression Searches](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/resources/sample_vaults/Tasks-Demo/Filters/Regular%20Expression%20Searches.md).
155
+
156
+
### Searching the start of a field
157
+
158
+
Find tasks whose description begins with Log, exact capitalisation:
123
159
124
160
```text
125
-
# Find tasks whose description begins with Log, exact capitalisation
126
161
description regex matches /^Log/
162
+
```
163
+
164
+
---
127
165
128
-
# Find tasks whose description begins with Log, ignoring capitalisation
166
+
Find tasks whose description begins with Log, ignoring capitalisation
167
+
168
+
```text
129
169
description regex matches /^Log/i
130
170
```
171
+
172
+
### Finding tasks that are waiting
173
+
174
+
I want to find tasks that are waiting for something else. But 'waiting' can be spelled in several different ways:
175
+
176
+
```text
177
+
description regex matches /waiting|waits|wartet/i
178
+
```
179
+
180
+
### Finding times
181
+
182
+
Find tasks containing a time in the description - simple version. This matches invalid times, such as `99:99`, as `\d` means 'any digit'.
183
+
184
+
```text
185
+
description regex matches /\d\d:\d\d/
186
+
```
187
+
188
+
---
189
+
190
+
Find tasks containing a time in the description. This is more precise than the previous example, thanks to specifying which digits are allowed in each position.
191
+
192
+
```text
193
+
description regex matches /[012][0-9]:[0-5][0-9]/
194
+
```
195
+
196
+
### Finding sub-tags
197
+
198
+
Currently `tag` and `tags` searches do not yet support regular expressions. Therefore, for precise searching of tags, use `description` instead.
199
+
200
+
Suppose you wanted to search for tags of this form: `#tag/subtag3/subsubtag5`, where the `3` and the `5` are allowed to be any single digit.
201
+
202
+
- We can use either `[0-9]` or `\d` to match a single digit.
203
+
- To find a sub-tag, any `/` characters must be 'escaped' to prevent them truncating the rest of the search pattern.
204
+
205
+
Escaping the `/` leads us to this instruction, which we have made case-insensitive to find capitalised tags too:
0 commit comments