Module: Zxcvbn::Matchers::RegexHelpers Private

Included in:
Digits, Year
Defined in:
lib/zxcvbn/matchers/regex_helpers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Shared helper for iterating non-overlapping regex matches over a password.

Instance Method Summary collapse

Instance Method Details

#re_match_all(regex, password) {|match, re_match| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Yields a Zxcvbn::Match and the underlying MatchData for every non-overlapping occurrence of regex in password.

Parameters:

  • regex (Regexp)

    pattern to search for

  • password (String)

    the password to search

Yield Parameters:

  • match (MatchBuilder)

    match with i, j, and token set

  • re_match (MatchData)

    the underlying MatchData object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zxcvbn/matchers/regex_helpers.rb', line 20

def re_match_all(regex, password)
  pos = 0
  while (re_match = regex.match(password, pos))
    i, j = re_match.offset(0)
    pos = j
    j -= 1

    match = MatchBuilder.new(i:, j:, token: password.slice(i, j - i + 1))
    yield match, re_match
  end
end