Dataview FLATTEN regexreplace help?

What I’m trying to do

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 trying to remove the "1.x - " part in the “Type” columns, so I’ll have the two groups called respectivelly “Working” and “Ideas”.

I’m a total noob with dataview and I built the dataview snippet by searching little pieces all over this forum. Thank’s for helping.

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:

  regexreplace(file.folder, ".*\/\d+(?:\.\d+)* - ([^\/]+)", "$1") 

Explanations follows:

  • .*\/ – 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.

It works properly. I’ll also study your amazing explaination of what the command is doing. I really appreciate your kind contribution, have a good day :smiley:

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