I have a dataview table that list files contained in two separate folders grouped by those folder, the result is this:
TABLE rows.file.link as "Note"
FROM "1 - Folder/1 - Journal"
FLATTEN regexreplace(file.folder, "^(.*/)(.+)$", "$2") AS s_file_parent_name
WHERE file.name != s_file_parent_name and file.name != "📜 Index" and file.name != "Material to check"
and file.folder != "1 - Folder/1 - Journal/1.2 - Learnings"
sort file.ctime asc
GROUP BY s_file_parent_name as Type
SORT Type desc
I’m out on thin ice here, as I don’t quite see the entire folder and file name structure you’re using, but maybe something like the following would work:
.*\/ – Gobble up everything until and including a forward slash
\d+ – Match digits, \d, that is one or more digits, +
(?: ... )*– Optionally followed by zero or more, *, non-capturing group, (?: ... ) of:
\.\d+ – Sequences of a literal period, \., and a number, \d+
- – Matching the literal sequence of - , a dash with spaces on both sides
( ... ) – A capture group consisting of:
[^ ... ]+ – A non matching character class, [^ ... ], with at least one, +, character not matching:
\/ – The literal forward slash. This sequence helps anchoring the regex, and allows for the first wildcard match to be gready and get all preceding sub-folders
Since the last group was a capture group, we can use that as the replacement text, "$1". This group should strip away number sequences in front of stuff like 1 - Something, 1.12 - Another one, or 127.0.0.1 - Loopback address.
PS! I’ve not looked at the rest of query for any optimisations or such.