What I’m trying to do
I’m trying to extract the second level folder name from the file.folder path for each row as a column in my dataview table. I can get it work as a group by, but I don’t want to group it. I want to see each file name as a linked file and the second level folder name. I’m only looking in one top level folder. I would like to do this without using dataviewjs.
Things I have tried
Searched this forum, I’ve read up on regex, I’ve tested on regex101, I’ve looked through the dataview functions page for other approaches than regex like split and substring.
I tried FLATTEN split twice and it’s great but doesn’t seem to display it as a column unless I group it, which I don’t want.
I tried splitting a split within the columns of the dataview, which seems to be something I made up that isn’t possible, lol.
I tried to use substring but couldn’t figure out how to pass through a dynamic position number for the start and stop points of the substring.
I tried the regex in the query below (the column named “Building”) and it’s the closest I’ve gotten. It works perfectly in regex101, but when I put it in my dataview query, I just get the full file.folder path which makes me think maybe the positive lookbehind and look ahead don’t work? Here is my full query. The “Box” column is working perfectly, it’s the “Building” column I can’t get to work.
TABLE
min(regexreplace(file.folder, "(?<=All Items\/)(.*?)(?=\/)", "$1")) AS "Building",
min(choice(length(firstcontainer)=0,regexreplace(file.folder, ".*\/([^\/]+)$", "$1"),firstcontainer)) As "Box"
From #puzzles
I’m not going to share a screenshot because my results have info I don’t want to display, but the folder structure I’m querying looks like this, a couple of examples:
All Items/Storage Building/Box Name
All Items/Home Building/Room Name/Box Name
If you put these examples in regex101 you can see it works perfectly, screenshot:
But in dataview, what I’m getting is just the exact same text back (full file.folder) without any replacement seeming to have happened.
I barely understand regex at the moment, I’ve just started a beginner tutorial this week to understand it better so apologies if I’m missing something obvious despite my attempts to research and troubleshoot.