Adding RegEx to Git Secrets

812 Views Asked by At

I'm attempting to add some RegEx password patterns to git secrets using the --add switch.

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&]).{6,40}$ ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$

When I do just a base git secrets --scan command I'm getting fatal: command line and I'm also getting Invalid preceding regular expression so I am thinking that perhaps I messed up the RegEx.

When I scan a particular file I get the following output:

grep: repetition-operator operand invalid

Not sure what I'm missing here. Thanks in Advance!

I expect no errors when running git secrets --scan or git secrets --scan somefile.whateverext

1

There are 1 best solutions below

0
On

The pattern as a string has to be escaped according
to the rules of the tool that parses the command line.

Some examples:

Double quote C-style "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[0-9]).{6,40}$"

Single quote '^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$'

Double quote raw r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$"

Single quote raw r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$'

Dot-Net Verbatim @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$"