查找bcrypt哈希的正则表达式? [英] Regular expression to find bcrypt hash?
问题描述
我正在寻找使用正则表达式(在PowerGrep中)在数据库中找到bcrypt哈希字符串的方法.
I am looking to find bcrypt hash string using regex (in PowerGrep), in a database.
尝试过此正则表达式:
{?A-Za-z_0-9.{60}}?
但未找到匹配项. Bcrypt哈希长度为60个字符,以"$ 2y $"开头.
But no match was found. Bcrypt hash is 60 characters length, and starts with "$2y$".
示例:
$2y$15$nK/B6u765645/lo0867h56546v/BnH5U5g45Aj67u67nMVtrhryt6
推荐答案
更新:
由于y
值旁边可能存在a
或b
,因此您可以使用
Since beside the y
value there might be a
or b
, you may use
^\$2[ayb]\$.{56}$
请参见 regex在线演示. 详细信息:
-
^
-字符串的开头 -
\$
-文字$
字符(应以正则表达式模式进行转义以匹配文字$
字符,否则,它将表示字符串的结尾) -
2
-一个2
char -
[ayb]
-一个字符类与指定集中的任何单个字符匹配 -
\$
-一个$
字符 -
.{56}
-除换行符之外的任何56个字符(如果使用了不符合POSIX的正则表达式引擎,否则它将匹配任何字符;要匹配常见NFA引擎中的任何字符,请用[\s\S]
替换.
或使用相应的DOTALL
标志) -
$
-字符串结尾.
^
- start of a string\$
- a literal$
char (it should be escaped in a regex pattern to match a literal$
char, else, it will denote the end of string)2
- a2
char[ayb]
- a character class matching any single char out of the specified set\$
- a$
char.{56}
- any 56 chars other than line break chars (if not POSIX compliant regex engine is used, else, it will match any chars; to match any chars in common NFA engines, replace.
with[\s\S]
or use a correspondingDOTALL
flag)$
- end of string.
原始答案
您的正则表达式-{?A-Za-z_0-9.{60}}?
-包含的范围不在字符类[...]
内,但在可选的花括号内,因此它们表示文字字符序列.请参阅您的正则表达式演示,以了解我的意思.
Your regex - {?A-Za-z_0-9.{60}}?
- contains ranges not inside a character class [...]
, but inside optional curly braces, and thus they present sequences of literal characters. See your regex demo to see what I mean.
您可以使用以下正则表达式:
You can use the following regex:
^\$2y\$.{56}$
请参见演示
^
匹配字符串的开头,\$2y\$
逐字匹配$2y$
(因为$
是一个特殊字符,需要转义),而.{56}
是其余56个字符.
The ^
matches the start of string, \$2y\$
matches $2y$
literally (as $
is a special character and needs escaping) and .{56}
is the rest 56 characters.
这篇关于查找bcrypt哈希的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!