Re.findall() & Re.finditer()

Sort by

recency

|

381 Discussions

|

  • + 0 comments

    import re pattern= r"(?<=[^AEIOUaeiou])([AEIOUaeiou]{2,})(?=[^AEIOUaeiou])"

    S = re.findall(pattern, input())

    if S: print(*S, sep="\n")

    else: print(-1)

  • + 0 comments

    import re

    pattern= r"(?<=[^AEIOUaeiou])([AEIOUaeiou]{2,})(?=[^AEIOUaeiou])" S = list(re.finditer(pattern, input()))

    if S: for i in S: print(i.group())

    else: print(-1)

  • + 0 comments
    import re
    s = input()
    pattern = r'(?<=[^aeiouAEIOU])([aeiouAEIOU]{2,})(?=[^aeiouAEIOU])'
    matches = re.findall(pattern, s)
    
    if matches:
        print(*matches, sep='\n')
    else:
        print(-1)
    
  • + 0 comments

    In case you are having issues like me to check if the iterator it's empty with the solutions here:

    import re
    matches = re.finditer(r"(?<=[^aeiouAEIOU])([aeiouAEIOU]{2,})(?=[^aeiouAEIOU])", input())
    found = False
    
    for word in matches:
        print(word.group(1))
        found = True
    if(not found):
        print(-1)
    
  • + 0 comments
    import re 
    S = input().strip()
    m = re.findall(r"(?i)(?<=[^aeiou])([aeiou]{2,})(?=[^aeiou])", S)
    if m: 
        print("\n".join(m))
    else:
        print(-1)