Could someone check my regex for single letter folder names is correct?

I’d be very grateful if someone could help me verify if I’ve done this correctly - I’m not convinced I have it right!

I’ve helpfully for me, but unhelpfully for my regex skills, named some of my key folders a, g, p and r!

In my graph view or search, would this regex be correct for fetching everything under the p folder?

path:/(^p\/)/ and -path:/(^p\/\_)/

Same for the tasks plugin, I’ve used this query, is there a neater/easier way to do this?

not done
path regex matches /(^p\/)/
path regex does not match /(^p\/\_)/
group by filename

I think you can loose the parentheses, as you don’t need to capture the groups, and then your regex should be matching everything which starts with the single letter p as the first folder, and neither any files starting with _ within that folder.

The regexes could possibly be combined into one using lookaheads, but the readability goes out the window very fast then. I’m on mobile now, so can’t test that just now.

1 Like


When I was working it out I was thinking of using look aheads but I read a thread (when I was trying to set up the queries for the tasks plugin) that it’s unpredictable or it might be slow so I figured I’d keep it simple(r)!

I’ve removed the brackets and done some more tweaking so now I have a colourful graph view too!

1 Like

For future regex needs I’d recommend using this resource:

It has helped me countless times when writing complex regex, so thought I’d mention it.

1 Like

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