Page 1 of 1
Limit Matched Pattern to 1 when re-naming file

Posted:
Tue Jul 22, 2025 8:13 am
by stewartad
Hi
I've set up a rule that finds a pattern of text in the contents of a PDF, and re-names the PDF with that pattern.
The problem I'm running into is that the rule is finding more than one instance of the pattern in the PDF. And therefore renames the PDF with pattern more than once i.e. 'matched_pattern matched_pattern matched_pattern.pdf'
I would like to adjust the rule so the PDF is renamed with the pattern only once, so the result is 'matched_pattern.pdf' no matter how many times the pattern is found.
Hope that makes sense.
Re: Limit Matched Pattern to 1 when re-naming file

Posted:
Tue Jul 22, 2025 8:36 am
by Mr_Noodle
Can you post your rule? Note that you can't upload images here. If you don't have your own cloud sharing service, you can host your image at imgur.com.
Re: Limit Matched Pattern to 1 when re-naming file

Posted:
Tue Jul 22, 2025 9:20 am
by stewartad
Re: Limit Matched Pattern to 1 when re-naming file

Posted:
Wed Jul 23, 2025 8:44 am
by Mr_Noodle
What is the actual text it is matching? Do you actually want the arbitrary text before and after _SellSheet_ stored in that attribute? It will grab all the text to the beginning and end of that line.
Re: Limit Matched Pattern to 1 when re-naming file

Posted:
Wed Jul 23, 2025 1:47 pm
by stewartad
Thanks for coming back.
I want Hazel to find anything_SellSheet_anything in the content of the PDF i.e.
PENN_SellSheet_Spinning Reel Z
then rename the PDF to PENN_SellSheet_Spinning Reel Z.pdf
To be clear, that works fine.
But if that pattern of text is repeated in the content, say 2 times, then Hazel stores the pattern twice and renames the PDF like this:
PENN_SellSheet_Spinning Reel Z PENN_SellSheet_Spinning Reel Z.pdf
===
NO NEED TO REPLY.
I now understand that "anything" REALLY MEANS anything.
Thanks again.
Re: Limit Matched Pattern to 1 when re-naming file

Posted:
Thu Jul 24, 2025 9:31 am
by Mr_Noodle
You can add another condition which is like your original pattern but matches everything up to the next _SellSheet_. You can have both conditions ORed together (see nested conditions on how to do that) with the new condition you just created appearing before your original one.