Sort by

recency

|

312 Discussions

|

  • + 0 comments

    \1 can be used inside of the lookahead even if the group is declared outside of it, wich enhance visibility and compehensiveness in that case.

    regex_integer_in_range = r"^[1-9]{1}[0-9]{5}$"
    regex_alternating_repetitive_digit_pair = r"(.)(?=.\1)"
    
    
    import re
    P = input()
    
    print (bool(re.match(regex_integer_in_range, P)) 
    and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
    
  • + 0 comments
    regex_integer_in_range = r"^[1-9]\d{5}$"
    regex_alternating_repetitive_digit_pair = r"(?=(.).\1)"
    import re
    P = input()
    print (bool(re.match(regex_integer_in_range, P)) 
    and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
    
  • + 0 comments
    regex_integer_in_range = r"^[0-9]{6}$"
    regex_alternating_repetitive_digit_pair = r"([0-9]{1})(?=[0-9]{1}\1)"	
    
  • + 0 comments
    regex_integer_in_range = r"^[100000-999999]{6}$"	# Do not delete 'r'.
    
    # Not more than one ARD pair
    regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)"	# Do not delete 'r'.
    
    '''
    source: StackOverflow
    
    Explanation:
    
    (\d): Match and capture a digit in group #1
    
    (?=: Start lookahead
    
    \d: Match any digit
    
    \1: Back-reference to captured group #1
    
    ): End lookahead
    '''
    
    
    import re
    P = input()
    
    print (bool(re.match(regex_integer_in_range, P)) 
    and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
    
  • + 1 comment
    regex_integer_in_range = r"^[1-9]\d{5}$"	# Do not delete 'r'.
    regex_alternating_repetitive_digit_pair = r"(?=(.).\1)"	# Do not delete 'r'.