I’d like to search all notes that matches exactly with a given tag (and ignores any subtags).
For example:
Notes:
Note1 (#action)
Note2 (#action/p1)
Goal:
Search all notes with the tag #action but not #action/p1, etc.
Expected Result:
Note1
Things I have tried
Things I have tried:
Click action tag in tag pane: returns Note1, Note2
tag: action: same as 1)
tag: #action: same as 1)
tag: "action": empty results
Right-click on action in tag pane, and no option to search with exact match.
Works but flawed:
Regex /^#action$/: Searches notes that has text #action in codeblock
Solution Ideas
If there aren’t any that work:
tag: "action" or tag: action$ for exact match (some special characters)
tagregex: /^action$/ (regex-version of tag)
Path-like search in tags (didn’t think about backward compatibility but you get the idea…)
tag: action → exact match
tag: action/* → all notes with direct subtags of action
tag: action/**/* → all notes with all subtags of action
tag: action/**/* -tag: action → All notes only with subtags of action
Right-click on a tag in a tag pane and there is search for #action exact match
Thinking further, the most flexible way would be introducing tagregex or making tag accept regex + hiding its complexity behind context menu for exact search.
Suggestion for Doc:
Working with Tags says clicking a tag returns an exact match, but in the app, it also returns all the notes with the tag’s subtags, which in my opinion is not an exact match.
Why does the forum thread template show “Things I have tried” first and “What I’m trying to do” later? It seems natural to reverse the order.
I just found this post, who also suffers from the lack of a way to search by tag (exact match). And I like the suggestion there, too (except that it changes UX) I’d love to see a discussion on providing a way to do exact match tag search, without any side-effects (unlike general search using regex).
If subtags are always separated by forward slashes, main tags can be isolated by negating the forward slash with regex. The following works in my tests of your samples to only find #action and to ignore #action/p1:
Thanks. It looks similar to one of “things I’ve tried”. It treats the entire text holistically and finds things that aren’t actually a tag i.e. text in a code-block, no?
Nice, you discovered a good case that my regex can’t find: which is a tag immediately followed by a disallowed character in tag like ,)`: #action,#keyword(#today) or any inline codeblock, which explains for your 4 bullet points.
$ marks an end of a word, which is an encounter with whitespace or end of the file.
What I’m puzzled about is your Obsidian not finding #action in non-inline codeblock. Mine finds it: