Regular Expressions

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Regular Expressions Sat Sep 01, 2012 4:43 pm • by zoom
My Desktop and Downloads are getting especially junky. With that I decided I would give Hazel a demo. I download and installed. The first rule I go to create was one to deal with Facebook image downloads; however, I cannot seem to distinguish between a Facebook image like 578738_10151152958642494_1230119189_n.jpeg and non-Facebook images like zoom_zoom.jpg. Why? Because there is no means to do a simple regular expression like \d{6}_\d{17}_\d{10}_n.jpeg.

I did a NoodleSoft forum search on "regular expression" and found an old discussion, which led me to believe regular expressions would never see the light of day in the app. I appreciate that regular expressions can be difficult for users or even the developer(s), but please don't sell all us users short. If we really are that dumb, then make it an "advance feature" option.

I have only given Hazel about 30 seconds. If I might have missed a means of doing the above, or missed more recent discussions on the additional of regular expressions -- then I apologize in advance. If I can't do a simple task like above, then I will delete Hazel and move on.
zoom
 
Posts: 1
Joined: Sat Sep 01, 2012 4:27 pm

Re: Regular Expressions Sun Sep 02, 2012 3:57 am • by Kha
There is a way to make this work. It is a bit fiddly but it is doable. You can specify which pictures get matched if you use the following rules:

1- Kind is image
2- Name matches...

In the name matches field, you will need to do the following. Add 6 'digit' tokens, then underscore, then 17 'digit' tokens, then an underscore...etc. This will tell Hazel to look for files that have the exact pattern that you are looking for before it runs the rules.
Kha
 
Posts: 15
Joined: Sat Dec 19, 2009 1:28 am

Re: Regular Expressions Sun Sep 02, 2012 4:06 am • by Kha
Please note that while I haven't tried to build the rule myself, the concept of it sounds like something that Hazel can handle with no problems. I personally have not tried cramming that many tokens in one rule before, and I don't know if it is possible to do that or not, but this is a route you can try with your own experimentations.

Another way of doing it is to use the 'number' token to replace any group of subsequent 'digit' tokens. This one will basically take any number, whether it is made of a single digit or 17, and use that as a rule. This means that in your case, you are basically telling hazel the following:

Code: Select all
If the name of the file matching the following pattern [numbers]_[numbers]_[numbers]_n.jpeg then do the following actions to it...


While this is less granular than the rule you want, it is also easier to make and should work just fine. I mean, what are the chances you will get files from a place other than Facebook that will have a similar pattern as the one above? :)
Kha
 
Posts: 15
Joined: Sat Dec 19, 2009 1:28 am

Re: Regular Expressions Tue Sep 04, 2012 5:06 pm • by Mr_Noodle
As mentioned, please search the help for "match patterns". It does pattern matching without exposing the user to regex, which can be a nightmare. If you insist on using regex directly for some reason, you can use a script to call out to the language of your choice.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion