HackerRank Python - Validating Postal Codes


Your task is to provide two regular expressions regex_integer_in_range and regex_alternating_repetitive_digit_pair

  1. regex_integer_in_range = r'^[1-9][\d]{5}$' # Do not delete 'r'.
  2. regex_alternating_repetitive_digit_pair = r'(\d)(?=\d\1)' # Do not delete 'r'.
  3. import re
  4. P = input()
  5. print (bool(re.match(regex_integer_in_range, P))
  6. and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

download android app