Re.findall() & Re.finditer()

Sort by

recency

|

367 Discussions

|

  • + 0 comments
    import re 
    
    S = input()
    a=map(lambda x: x.group(),re.finditer(r'(?<=[qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM])([A,E,I,O,U,a,e,i,o,u]{2,})(?=[qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM])',S))
    q=list(a)
    k=bool(q)
    if k==False:
        print('-1')
    else:
        for t in q:
            print(t)
    
  • + 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')
    
  • + 0 comments
    import re
    
    pattern = r'(?<=[qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM])([aeiouAEIOU]{2,})(?=[qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM])'
    results = list(re.finditer(pattern, input()))
    print(*[x.group(1) for x in results] if results else [-1], sep="\n")
    
  • + 2 comments
    import re
    
    s = input()
    vowels = "aeiouAEIOU"
    consonants = "qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM"
    
    pattern = r'(?<=['+consonants+'])(['+vowels+']{2,})(?=['+consonants+'])'
    
    matches = re.findall(pattern, s)
    
    if matches:
        for match in matches:
            print(match)
    else:
        print(-1)
    
  • + 0 comments
    import re
    
    pattern = r'(?<=[^aeiouAEIOU])([aeiouAEIOU]{2,})(?=[^aeiouAEIOU])'
    
    s = input()
    
    matches = re.findall(pattern, s)
    
    if matches:
        for match in matches:
            print(match)
    else:
        print(-1)