Match exact string from list of options

I am using pre-commit to run some hooks, and I have a regex where I only include a list of files (dirs) that I wish to run the hook on. The problem is that my regex matches exact string + any other appending string to the first string.

hooks:
- id: xdoc
  files: (?=(analytic|authentication|store))
  exclude: (?=(apps|serializers|admin|test|migrations|__init__.py))
  stages: [commit]

here I have initially two apps starting with the string store:

store
storespecifics

The above regex matches both, where I am only trying to match exact store. I tried for example (?=^(analytic|authentication|store)$), but nothing gets matched.


there's no need to involve positive lookaheads here as pre-commit uses re.search to match paths -- this is probably closer to what you want:

        files: ^(analytic|authentication|store)/
        exclude: (apps|serializers|admin|test|migrations|__init__.py)

note that I use a / here to make sure we're at a folder boundary (matching store/foo.py but not storespecifics/foo.py)

I also anchor the match to the beginning with ^, if that's not desirable you'd probably replace the ^ with a /


disclaimer: I wrote pre-commit