Re.findall() & Re.finditer()

  • + 0 comments
    import sys, re
    
    VOWELS, CONSONANTS = "aeiou", "qwrtypsdfghjklzxcvbnm"
    S = sys.stdin.read()
    
    match_iter = re.finditer(rf"(?<=[{CONSONANTS}])[{VOWELS}][{VOWELS}]+(?=[{CONSONANTS}])", S, flags=re.I)
    first_match = next(match_iter, None)
    
    #Check if iterator is empty
    if first_match: 
        print(first_match.group())
        for match in match_iter:
            print(match.group(), sep='\n')
    else:
        print('-1')