Home Writing

til / improving dataview query using regexmatch

Previously, I mentioned a Dataview query that I have in Obsidian for displaying “Input/output” on my daily notes page. The query looked like this:

LIST WHERE file.cday = date("2022-08-05") AND file.name != "2022-08-05"

This displays any file created today, but not the current daily notes page itself. However, sometimes I’ve gone back/forward in time and manually created a daily notes page. Those pages would still show up using this query and I don’t want any daily notes in the list.

Luckily, Dataview has a regexmatch function that I can use to filter these out. I’m using ISO dates in the format YYYY-MM-DD. This means I can use this regex pattern: \d{4}-\d{2}-\d{2}. It matches any four numbers, a hyphen, any two numbers, a hyphen, and any two numbers.

Using this, the modified query becomes:

LIST WHERE file.cday = date("2022-08-05") AND regexmatch("\d{4}-\d{2}-\d{2}", file.name) = false

Now I’ll never see a daily notes page in my daily input/output list.

I’m using this together with Templater to avoid any manual work. Whenever I enter a new day, a new daily notes page is automatically created and today’s date is added. Here’s the actual query in my template, which also includes sorting:

LIST WHERE file.cday = date("<% tp.date.now("YYYY-MM-DD") %>") AND regexmatch("\d{4}-\d{2}-\d{2}", file.name) = false SORT file.name ASC

  • Loading next post...
  • Loading previous post...