Task You are given a string . It consists of alphanumeric characters, spaces and symbols(+,-). Your task is to find all the substrings of the origina string that contain two or more vowels. Also, these substrings must lie in between consonants and should contain vowels only.
Input Format: a single line of input containing string .
Output Format: print the matched substrings in their order of occurrence on separate lines. If no match is found, print -1.
Sample Input:
rabcdeefgyYhFjkIoomnpOeorteeeeetSample Output:
ee
Ioo
Oeo
eeeee
The challenge above was taken from https://www.hackerrank.com/challenges/re-findall-re-finditer
The following code passes all the 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 doesn't.
import re
sol = re.findall(r"[^aiueo]([aiueoAIUEO]{2,})[^aiueo]", input())
if sol:
for s in sol:
print(s)
else:
print(-1)
The only difference beteen them is the final bit of the regex. I can't understand why the second code fails. I would argue that ?= is useless because by grouping [aiueoAIUEO]{2,} I'm already excluding it from capture, but obviously I'm wrong and I can't tell why.
Any help?