Query main tag only, not subtags

I’m trying to create a query that will give me the results of the main tag, without the subtags. (e.g, #todo but not #todo/today and #todo/sometime).

I’ve tried:

```query
tag: #todo
```
```query
#todo
```

I’ve tried adding a space at the end of todo in the query but it is ignored.

→ Results: Everything I’ve tried always includes files tagged as #todo/sometime.

→ Is there a simple way to do it with Obsidian?

(I know I use Regex or I can iterate all of the tag/subtags I use and exclude them in the query but that’s just so cumbersome.)

Did you try

```query
"#todo "
```

?

Or perhaps like this, because adding a space will not work if you have a line break after the tag.

```query
tag: #todo -"todo/"
```

The only problem with this query is that the -“todo/” queries notes, not tags. So if you have #todo in one part of your note, but #todo/foo later in the note, then it won’t return the note at all. So maybe there is a better query to use.

As rigmarole suggests below, it isn’t just the ending but also the beginning that is at issue. If I add use “space#todospace” then I miss out on all tags that start at the beginning of a line.

If I remove the first space results include links files that include subheadings, e.g., [[Link to this file#ToDo]]

Oddly enough, tag: #todo -tag:#todo/ in search still includes a file that is tagged with #todo/sometime. I would have thought the last forward slash might have prevented that, but alas.

My example uses a content query. You are searching for the tag #todo/ which is not the same as #todo/sometime. The tag query is an exact match, not fuzzy. (I don’t know if there is a way to make it fuzzy, or use wildcards.)

I think I’ll just give up on nested tags. I only just tried them in the last couple of days, and if it is this problematic to do what should be a simple query, I can’t imagine what it would be like to do more complex queries with them.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.