1

我正在尝试使用 --add 开关将一些 RegEx 密码模式添加到 git 机密中。

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

当我只做一个基本的 git secrets --scan 命令时,我得到了fatal: command line,我也得到了Invalid preceding regular expression,所以我想也许我搞砸了 RegEx。

当我扫描特定文件时,我得到以下输出:

grep: repetition-operator operand invalid

不知道我在这里缺少什么。提前致谢!

我希望在运行 git secrets --scan 或 git secrets --scan somefile.whateverext 时不会出错

4

1 回答 1

0

作为字符串的模式必须根据
解析命令行的工具的规则进行转义。

一些例子:

双引号 C 样式 "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[0-9]).{6,40}$"

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

双引号原始r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$"

单引号原始 r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$'

点网逐字记录 @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[0-9]).{6,40}$"

于 2019-07-22T22:59:34.403 回答