Method: Exec::CheckParameter#match_regex

Defined in:
lib/exec/check_parameter.rb

#match_regex(str, regexp, msg_if_nok) ⇒ Boolean, String (private)

Check if a string matches a regex

Parameters:

  • str (String)

    The string to check.

  • regexp (Rexexp)

    The regular expression.

  • msg_if_nok (String)

    The message to return if str doesn’t match with regex

Returns:

  • (Boolean, String)

    true,“” if msg matched with regex, false, msg_if_nok if doesn’t.



197
198
199
200
201
202
203
204
205
206
# File 'lib/exec/check_parameter.rb', line 197

def match_regex(str, regexp, msg_if_nok)
  msg = ""
  valid = true
  regex=Regexp.new(regexp)
  unless str.match(regex)
    valid = false
    msg = msg_if_nok
  end
  return valid, msg
end