Skip to content

Conversation

@nijel
Copy link

@nijel nijel commented Jan 29, 2025

It is not obvious that newline is included in the matched line and it took me quite some time to figure out.

It is not obvious that newline is included in the matched line and it took me quite some time to figure out.
@asottile
Copy link
Member

this is already specified as a python regex so this behavior should be expected. also $ will match already without the new line being part of the pattern

@asottile asottile closed this Jan 29, 2025
@nijel
Copy link
Author

nijel commented Jan 29, 2025

Hmm, it indeed does match for this simple case, but it doesn't work like that for all regexp. Sorry for providing a bad example.

What I wanted to catch:

* This is a correct changelog entry with a stop.
* This is an invalid entry

This doesn't work as expected because [^.] is consumed by \n:

  - id: rst-bullet-stop
    name: Changes end with a stop
    description: Bullet list in changes should end with a stop.
    files: docs/changes\.rst
    entry: ^ *\* .*[^.]$
    language: pygrep

This does work:

  - id: rst-bullet-stop
    name: Changes end with a stop
    description: Bullet list in changes should end with a stop.
    files: docs/changes\.rst
    entry: ^ *\* .*[^.]\n$
    language: pygrep

@asottile
Copy link
Member

yeah that's just how regex works. nothing special here

@asottile
Copy link
Member

your character class is too greedy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants