Re.findall() & Re.finditer()

Sort by

recency

|

373 Discussions

|

  • + 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)
    
  • + 0 comments

    Here is HackerRank Re.findall() & Re.finditer() in python solution - https://programmingoneonone.com/hackerrank-re-findall-re-finditer-solution-in-python.html

  • + 0 comments

    import re

    S = input()

    vowels = 'AEIOUaeiou' consonants = 'QWRTYPSDFGHJKLZXCVBNMqwrtypsdfghjklzxcvbnm'

    pattern = fr"(?<=[{consonants}])([{vowels}]{{2,}})(?=[{consonants}])"

    matches = re.findall(pattern, S)

    if matches: for x in matches: print(x) else: print(-1)

  • + 0 comments

    import re

    pattern = re.compile(r"(?<=[QWRTYPSDFGHJKLZXCVBNMqwrtypsdfghjklzxcvbnm])[AEIOUaeiou]{2,}(?=[QWRTYPSDFGHJKLZXCVBNMqwrtypsdfghjklzxcvbnm])")

    for x in re.findall(pattern, input()) or [-1]: print(x)

        remove the extra logic and just force a -1 
    
  • + 0 comments
    import re
    text = input()
    vowels = 'aeiouAEIOU'
    consonants = 'qwrtypsdfghjklzxcvbnmQWRTYPSDFGHJKLZXCVBNM' 
    pattern = rf'(?<=[{consonants}])([{vowels}]{{2,}})(?=[{consonants}])'
    
    matches = re.findall(pattern, text)
    if matches:
        for match in matches:
            print(match)
    else:
        print(-1)