Limit Matched Pattern to 1 when re-naming file

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

Moderator: Mr_Noodle

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.
stewartad
 
Posts: 3
Joined: Tue Jul 22, 2025 7:57 am

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.
Mr_Noodle
Site Admin
 
Posts: 11998
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


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.
Mr_Noodle
Site Admin
 
Posts: 11998
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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.
stewartad
 
Posts: 3
Joined: Tue Jul 22, 2025 7:57 am

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.
Mr_Noodle
Site Admin
 
Posts: 11998
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support