Contain match too hungry?

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

Moderator: Mr_Noodle

Contain match too hungry? Wed Jun 08, 2022 6:09 am • by pascaldevink
I have notes in markdown that I want to move to a subfolder based on the first (or only) hashtag that they contain.

For example, this is the top of a certain note:
author:: Trev de Vroome
source:: [Book Summary: Accelerate](https://tdevroome.medium.com/book-summa ... 31efe4c34c)
clipped:: [[2022-05-23]]
published:: 2019-10-18

#resources/agile

# Book Summary: Accelerate

![](https://miro.medium.com/max/700/0*CJxxTI-GC7s6-y8C.jpg)

Accelerate, by Nicole Forsgren PhD, Jez Humble, and Gene Kim


I have created a rule that should match the tag and move it accordingly, using a custom attribute. It more-or-less works, but Hazel seems to either be too eager in matching or not match spaces/newlines at all, as it is matching the custom attribute as "agileBook" (ie. the last part of the tag that I want to match, but also the first word on the next line) :(

Here you can see the rule and what it matches:
Image

A closer look at the "resource" custom attribute, which contains only characters. According to the hover text, it should only match non-blank characters:
Image

And this is a closer look at the content Hazel seems to read:
Image

Am I missing something here? Is Hazel not reading my file correctly, is there something wrong with my matching pattern, or is Hazel just too hungry in matching?
I've tried adding a space at the end of my matching pattern, but that doesn't seem to have any effect :(
Last edited by pascaldevink on Wed Jun 08, 2022 8:42 am, edited 1 time in total.
pascaldevink
 
Posts: 4
Joined: Wed Jun 08, 2022 5:55 am

Re: Contain match too hungry? Wed Jun 08, 2022 8:42 am • by Mr_Noodle
The images aren't coming through but note that if you enter a space, it will match any amount of whitespace, including newlines. Every other match token will not cross newline boundaries.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Contain match too hungry? Wed Jun 08, 2022 8:43 am • by pascaldevink
I've updated the images, sorry about that.
As I mentioned, I tried both with and without a space after the matching pattern, but there seems to be no difference at all
pascaldevink
 
Posts: 4
Joined: Wed Jun 08, 2022 5:55 am

Re: Contain match too hungry? Thu Jun 09, 2022 8:18 am • by Mr_Noodle
# is a formatting character for a header in markdown. I think you need a space after it for it to be interpreted that way, which is why the first # is in the text content comes through, but not the second. Try removing the space between "#" and "Book" in your file.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Contain match too hungry? Thu Jun 09, 2022 8:24 am • by pascaldevink
A space between a # and the rest of the sentence indeed specifies a header (an h1 to be exact, as ## or ### or even #### can also be used for h2, h3, and h4 respectively) in markdown, and that line is a header.

I'm confused why that # in the header doesn't seem to show up in the preview (see the last screenshot). It seems to be completely gone somehow, which is why I think the match pattern seems to be too hungry, while it might actually be an issue with the input? Does Hazel do anything special to run the match pattern on a file?
pascaldevink
 
Posts: 4
Joined: Wed Jun 08, 2022 5:55 am

Re: Contain match too hungry? Thu Jun 09, 2022 8:29 am • by pascaldevink
To confirm my suspicion, I copied the markdown file and changed it into a regular .txt file. It has the exact same contents though.

Imagine my surprise when running the preview on this file, and Hazel was able to accurately detect the tag :shock:

Image
pascaldevink
 
Posts: 4
Joined: Wed Jun 08, 2022 5:55 am

Re: Contain match too hungry? Fri Jun 10, 2022 8:36 am • by Mr_Noodle
The text contents for Markdown are the actual text, not any formatting. It's like with HTML. You don't see all the various markup tags.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support