Dataview regex query to match all occurrences of a subtag

Things I have tried

I have tried to search the forum and dataview documentation for examples using regexmatch, where, or even contains to try to accomplish this.

What I’m trying to do

As a simplified example of what I am trying, I would like to be able to use regex within a Dataview query to create a table of links to the notes that have the tag #type/scene/ then any subtag followed by the /character subtag.

I am not so much interested in this specific use case as I am in finding out how I can use regex within Dataview queries. Based on my understanding and experimentation, regexmatch and regexreplace deal more with matching and manipulating strings for display after the query has occurred, but I have limited experience.

As a workaround, I know that I can just do an Obsidian embedded query utilizing regex. Unfortunately, I just can’t seem to find the solution to get the same kind of functionality in Dataview. I have to imagine there might actually be multiple ways to accomplish this. I am really interested in any and all techniques that may work, but in the end, I have a huge vault, so there is a bias towards higher performance. For example, I believe that Dataview calculates tag queries using from faster than doing the search manually using contains. But really, I’d like to know all the options if there are multiple, since some may have the benefits of more flexibility, etc.

Thanks for any suggestions. Even just a point in the right direction or a link to a possibly relevant example would be greatly appreciated.

Related: Searching for sub-tag

Hi.
I’m a dumb in regex… I know zero about it. :slight_smile:
But my first point is: in FROM you can’t use variables or functions: so, taking your example you just can use the FROM #type/scene, the maximum common value for all wanted sources.
It’s important to use some FROM to define the source precisely because your argument: the performance.
About the way to filter this type of tags - #type/scene/<something>/character - I stole the regex part from other help question - [^/]+ (a code that I don’t know well what it means) - and I suggest this:

TABLE file.etags
FROM #type/scene
WHERE filter(file.etags, (t) => regexmatch("#type/scene/[^/]+/character", t))

But I don’t know if it works…
Try and say something :slight_smile:

1 Like

@mnvwvnm It works! Thanks so much! You are such a knowledgeable and generous helper here on the forum. Honestly, I posted this topic thinking that you might be able to assist me. I really did try; and after seeing this solution, I am committed to really put in the time and at least try all the various commands described in the Dataview help.

You deserve a lot of credit for helping keep this community so positive and lively. I know that as I begin to learn more, I will be happy to take the time to try and share any little tidbits I’ve held onto that may be useful. A lot of the willingness to continue to try to help comes from inspiration from and appreciation for what you and others have done. I am sure many feel the same way.

I have recently gotten into regex and recognize the [^/]. I believe it matches any characters that are not /.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges#types

In the context of a nested tag, this makes a lot of sense. Thanks again! You’re making a big difference here time and time again.

3 Likes

@mnvwvnm Although it is still a work in progress, since yesterday, I created a regex reference note that I decided to share. With some polishing, it is increasingly becoming a decent Obsidian note substitute to the regex website I linked to above: Mdn web docs - Regular Expressions in Obsidian Search

Thanks again!

2 Likes

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