Pattern matching/regex type question

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Pattern matching/regex type question Sun Dec 08, 2019 9:07 am • by RobForsyth
Dear Hazel Community

I'm trying to raise my Hazel game and am uncertain if the following is possible (there seem to be some parallels with this thread https://www.noodlesoft.com/forums/viewtopic.php?f=2&t=9711&p=28881&hilit=regex#p28881 implying this may not be currently possible but might become so with anticipated enhancements?

I receive large numbers of documents relating to multiple projects. Projects have a consistent numbering format (four digits) and there are some reasonably consistent file naming conventions, but I am receiving incoming documents on multiple projects at any one time.

What I would like to do is sort incoming documents into a folder matched on the four digit number, then subfolders e.g. for the various stakeholders in the project. So "1234 external stakeholders report" would file into /1234 project/1234 stakeholder contributions

Whilst I can pattern match on "any four digit number at the start of a filename" how do you extract the *actual* four digit number to tell Hazel specifically into which of the several project folders this should be filed?

As supplemental questions:

1. what would be the most efficient way to handle the subfolder sorting: put complex nested watch rules on the downloads folder or a two-step process where the subfolder-sorting watch rules apply to the 1234 project folder itself? and
2. if the latter are there efficient/reliable ways to clone these rules to apply to new project folders as these get created?

Thanks!

Rob
RobForsyth
 
Posts: 7
Joined: Sun Dec 08, 2019 7:56 am

Re: Pattern matching/regex type question Mon Dec 09, 2019 12:16 pm • by Mr_Noodle
Look up "match patterns" in the manual. The chapter there will show you how to use custom attributes. You can do it all in one rule using the Sort into subfolder action. You can specify multiple folder levels using the right-pointing-triangle token.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Pattern matching/regex type question Mon Dec 09, 2019 3:41 pm • by RobForsyth
Thanks for the starter but I'm not there yet: I've created a rule with "name matches [1][1][1][1][…]" which is identifying the file(s) correctly. But I'm not clear about how to do the sort-and-move which requires extracting the *actual* (not fixed) four digit number from the match to tell Hazel specifically into which of several project folders this should be filed? To adopt a regex analogy I have the ([0-9]{4}) bit working but am unclear how to supply the "$1" to the "move to" part of the rule. Does that make sense?
RobForsyth
 
Posts: 7
Joined: Sun Dec 08, 2019 7:56 am

Re: Pattern matching/regex type question Tue Dec 10, 2019 11:26 am • by Mr_Noodle
You need to use a custom attribute, which is like a capture group.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Pattern matching/regex type question Tue Dec 10, 2019 12:04 pm • by RobForsyth
Got it now, thanks again
RobForsyth
 
Posts: 7
Joined: Sun Dec 08, 2019 7:56 am


Return to Support