这是解释该问题的 Ruby 代码:
1.8.7 :018 > pattern[:key] = '554 5.7.1.*Service unavailable; Helo command .* blocked using'
=> "554 5.7.1.*Service unavailable; Helo command .* blocked using"
1.8.7 :019 > line = '554 5.7.1 Service unavailable; Helo command [abc] blocked using dbl'
=> "554 5.7.1 Service unavailable; Helo command [abc] blocked using dbl"
1.8.7 :020 > line =~ /554 5.7.1.*Service unavailable; Helo command .* blocked using/
=> 0
1.8.7 :021 > line =~ /pattern[:key]/
=> nil
1.8.7 :022 >
正则表达式在直接用作字符串时有效,但在我将其用作哈希值时无效。