Searching for notes without links (orphaned notes)

Now that Obsidian supports regex searches with version 0.8.0, we can search for notes that don’t have links to other notes!

For this to work you’ll need to come up with a regex pattern that matches how your filenames are structured. A good help with that is https://regex101.com/.

Let’s go through an example. My filenames look like this:

[[2020-07-31 112421]]

To search for notes without those kind of links, I use this regex pattern in Obsidian’s search field:

-/\[\[[\\d\- ]+\]\]/

This is what the pattern means:

Character Meaning
- Negation; I want Obsidian to search for notes that do not contain this pattern.
/ Start of regex pattern (required).
\[ The first [ of the note links ([[...]]) properly escaped with \.
\[ The second [ from the start of the note links.
[ The start of a regex character class.
\\d A regex token that matches any digit character (0-9) properly escaped with \ for Obsidian’s search.
\- Looking for a literal ‘-’, which appear in my note’s filename format.
A literal space, which also appear in my note’s filename format.
] End of a regex character class.
+ Regex quantifier; repeat the preceding character class between one and an unlimited number of times.
\] The first ] of the end of the note link, escaped with \.
\] The second ] that marks the end of the note link.
/ End of regex pattern (required).

In regular English, the pattern says: "Look for any digits, -, and spaces between [[ and ]]". But with the - in front of the pattern, Obsidian look for notes that lack that pattern.

A nice thing about Obsidian’s new search is that we can also combine search terms. For instance, this looks for notes that have the #need-theory tag but don’t have a link to another note:

#need-theory -/\[\[[\\d\- ]+\]\]/

Let me know what you think or any ideas for improvement you might have.

Good luck searching notes that could use some improvement. :slight_smile:

10 Likes

This is super useful!

@Silver could we get a pinned thread, like the CSS one for useful regex searches?

3 Likes

This is only possible to work for notes whose title conforms to a certain format. Orphaned notes with a random title consisting of 1 or more words cannot be searched for, right?

I think that was the idea behind:

But the OP would need to update and organize with new resources.

Edit: but maybe you mean more of a list of useful regex for use in obsidian. This would be different and also a good idea

1 Like

Is there a way to find out which links are not leading to a page using RegEx?

1 Like

Yes the regex example I gave was for the file format I use, but you can tweak it to anything else.

Let’s say a vault has filenames that consist only out of words. Finding notes that don’t have those links requires this regex search:

-/\[\[[a-zA-Z ]+\]\]/

Here inside the pattern we look for any letter from ‘a’ to ‘z’ (a-z), any capital letter ‘A’ to ‘Z’ (A-Z), and possible spaces between words ( ). With the + we don’t care how often those letters and spaces appear, but we require at least one.

Such a pattern matches the following kind of links:

[[a]]
[[mynote]]
[[hello there]]
[[a note with a long title like this one for instance has]]

But of course the pattern also has limitations. It doesn’t match:

  • [[hello-there]] because there’s a dash between the words here.
  • [[2020 my example note]] because this link contains numbers.
  • [[hello there|see this study]] because of the | character.
  • [[my note.md]] because of the dot (.).
  • [[earlier studies, however, contradict]] because of the comma (,).

It’s probably good to have limitations in your pattern (I think so at least) so that you don’t end up matching things you aren’t interested in.


As an experiment we can also make a pattern that is much more flexible. Consider for instance this one:

-/\[\[[a-zA-Z0-9 \-\|\.,]+\]\]/

This search query looks for notes that miss [[...]] links. This time we allow our links to have the following:

  • Zero or more lowercased letters (a-z).
  • Zero or more uppercased letters (A-Z).
  • Zero or more digits (0-9).
  • Zero or more spaces ( ).
  • Zero or more dashes (\-).
  • Zero or more ‘|’ characters (\|).
  • Zero or more periods/dots (\.).
  • And zero or more commas (,).

Since we have the + again after the pattern, at least one of those 8 possibilities should be between [[ and ]].

With this much more flexible pattern we can have Obsidian look for these links:

[[a]]
[[1]]
[[mynote]]
[[hello there]]
[[a note with a long title like this one for instance has]]
[[hello there|see this study]]
[[my note.md]]
[[earlier studies, however, contradict]]
[[hello-there]]
[[2020 my example note]]
[[2020-06-16 080350]]

Any of these link formats are ‘caught’ by the regex pattern.


I’m always a bit hesitant with very flexible patterns since they might also catch situations we didn’t intend to find.

A good test in Obsidian is to remove the leading - from the query. That way we look for notes that do contain the pattern.

If the search pattern works well, the search query should turn up all the notes of which you know have links. If some of them don’t show up, then the links in those notes aren’t recognised by the pattern.

7 Likes

As far as I know we can only search for the text content of notes, but not validate what’s inside those notes.

1 Like

Wow!! Thanks a lot for that, you’re a real Regex expert. You must have been so happy when this was finally supported.

Yeah! This is where I was going. I don’t know regex (or css) and usually benefit from what other people share, so the pinned thread would be helpful.

@JkNML could I ask you to use your regex super powers for something? How would I/is it possible to search for files with incomplete/complete TODOs?

I certainly dont have regex super powers :laughing: but in version 0.8.1 and above these should work or at least get you started:

For incomplete todos - i.e. empty check boxes:
/- \[ \]/

And for completed TODOs - i.e. checked boxes:
/- \[x\]/

But unless you mark TODO check boxes with some other standard identifier (like “TODO:”) it may be hard to separate TODO lists from other check boxes - but maybe that is not a problem for you

4 Likes

Exactly what I needed, thanks!