Dataview plugin snippet showcase

Does anyone have a working example of the use of regexmatch in Dataview? I don’t seem to get it to work and have the impression that there is something major I am overlooking…

Here are the examples given in the docs:

regexmatch("\w+", "hello") = true
regexmatch(".", "a") = true
regexmatch("yes|no", "maybe") = false
4 Likes

Just a bit busy atm, but I’ll give it a try later :slight_smile:

Thank you, yes, I had seen those. I think what I am doing wrong must have to do with how I am trying to use this.

For example, I tried this:
WHERE file.name = (regexmatch(file.name, “A.*,”)

But I am not sure regexmatch can even be used in a WHERE statement.

1 Like

No worries. Mine is a long-term project. Thank you for thinking about this issue!

This should work:

where regexmatch("^A", file.name)

The ^ matches the start of a line, or in your case, the start of a file name.

So the whole query would be:

LIST FROM #author
WHERE regexmatch("^A", file.name)
SORT file.name ascending
9 Likes

Ah, wow, now I understand! Thank you very much. This is most helpful and eye-opening for my particular case of blindness!

2 Likes

where type = “test” and contains(location, “shoulder”)

totally worked… I was trying this but putting in contains(location, “shoulder”) = true

Thanks a bunch

1 Like

Always interesting to see different use cases

For yoga I can imagine shape difficulty, area (or muscle groups, or joints) targeted, position (supine, prone, sidelying, standing…)

My mind is on fire with possibilities :smiley:

1 Like

Short question: Does “contains(…)” work on arrays or on substrings? I.e., would it find “shoulder” only once in, say, a list like ("head", "shoulder", "shoulder height")?

2 Likes

Good question. I’m not exactly sure atm. I think this example would just return true.
But in an upcoming release, blacksmithgu is gonna make some of the functions vectorised so that contains(list: [], find: string) => boolean[]. In other words, it would return a list of true of false for each item in the list.
You could then use any(list) or all(list) to check if any or all of the values are true, respectively.

1 Like

It works on objects, lists, and strings.

https://blacksmithgu.github.io/obsidian-dataview/#/functions

3 Likes

Wondering if it can pick up sections from a group of pages. Like all of one section of my daily notes for a single page. That’d be amazing.

1 Like

Does anyone have examples of Group By?

I’m trying to figure out if what I want is possible. Assume a folder called Recipes, with subfolders like Appetizers and Drinks (I know I always use recipes but I find they work well with examples). I’d like the list to display as follows:

Recipes/Appetizers
item 1
item 2

Recipes/Drinks
item 1
item 2

I would actually prefer to hide the “Recipes” part of the path, but that’s a different matter.

This just gives me an empty list:

```dataview
list from "Recipes"
where file.name !="_Recipes TOC"
group by file.path
```
1 Like

Hey Lise. You can read my post here for a longer description of group by.
But basically, I think your codeblock should work with a minor change.
You’ve grouped the recipes properly, but now you need to ask for them to be displayed. You do this with the rows property, which I discuss more in that post.

But I think this should work:

list rows.file.link
from "Recipes"
where file.name != "_Recipes TOC"
group by file.path
4 Likes

Nevermind, this isn’t gonna work… file.path includes the note name in the path, not just the parent folder. This can be changed replacing the file.name in the path with nothing replace(file.path, file.name + ".md", ""). But this is only a cosmetic change; you can’t group by this replaced value

@SkepticMystic Thanks so much for giving it a go. I did read your wonderful explanation of group by.; I was hoping there was an example out there that used List rather than Table, thinking that might be why my attempt wasn’t working.

This is a query for your Daily Note template. When you generate a note from the template, the query will show all notes last modified on that daily note’s date.

As a list:

LIST
FROM "" 
WHERE date({{date:YYYY-MM-DD}}T23:59) - file.mtime <= dur(24 hours) and date({{date:YYYY-MM-DD}}T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc

Or as a table:

TABLE file.mtime as Modified
FROM ""
WHERE date({{date:YYYY-MM-DD}}T23:59) - file.mtime <= dur(24 hours) and date({{date:YYYY-MM-DD}}T23:59) - file.mtime > dur(0 hours)
SORT file.mtime asc
22 Likes

It looks like some people may have figured this out already (?) but after watching the interview with @EleanorKonik on @nickmilo 's YouTube channel, I figured I’d share how to use Dataview to single out an element a YAML property with multiple elements for those who came here for that reason. Assuming you have made a YAML property with multiple elements, you can use the Dataview command “where contains(property, element)” to isolate one of the elements. For example:

List from ""
WHERE contains(moc, "China")
11 Likes

Is it possible to have file.mtime render as a time only rather than, as now as a date and a time?