Find every two (non-overlapping) vowels between consonants

Task  You are given a string. It consists of alphanumeric characters, spaces and characters (+, -). Your task is to find all the substrings of the original string containing two or more vowels. In addition, these substrings must be between consonants and contain only vowels.

Input format: one line of input containing a line.

Output format: print matched substrings in the order they appear on separate lines. If no match is found, type -1. A.

Input Example: rabcdeefgyYhFjkIoomnpOeorteeeeet

Output result:

ee
Ioo
Oeo
eeeee


The task above was taken from https://www.hackerrank.com/challenges/re-findall-re-finditer

The following code passes all test cases:

import re

sol = re.findall(r"[^aiueo]([aiueoAIUEO]{2,})(?=[^aiueo])", input())

if sol:
    for s in sol:
        print(s)
else:
    print(-1)

The following fails.

import re

sol = re.findall(r"[^aiueo]([aiueoAIUEO]{2,})[^aiueo]", input())

if sol:
    for s in sol:
        print(s)
else:
    print(-1)

- . , . , ?= , , [aiueoAIUEO]{2,}, , , , , .

?

+4
1

, , , , , , , ( , , ).

import re
print(re.findall(r'[^aiueo]([aiueoAIUEO]{2,})(?=[^aiueo])', 'moomoom'))
print(re.findall(r'[^aiueo]([aiueoAIUEO]{2,})[^aiueo]', 'moomoom'))

['oo', 'oo']
['oo']

https://ideone.com/2Wn1TS

, . , . [b-df-hj-np-tv-z] [^aeiou] flags=re.I

+3

Source: https://habr.com/ru/post/1680806/


All Articles