Regex non exclusive group

Do you how can I get this result with Regex? In literal words, I want each groups of successives vowels with the maximum of consonants surrounding them (backward or foreward).

Example :

input : alliibaba 

outputs :

I tried :


but it returns distincts groups, so I don’t know if it’s possible with Regex…

Thanks you for any help.


You can put non-exclusive parts of the regex in lookaround patterns so that the search buffer is consumed only one character at a time. Since your rule appears to be that consonants are non-exclusive while vowels remain exclusive, you should group the consonants before vowels in a lookbehind pattern, consonants after vowels in a lookahead pattern, while the vowels themselves are also grouped to make for 3 capture groups, and then join the 3 groups into a string for output:

var re = /(?<=([bcdfghjklmnpqrstvwxyz]*))([aeiou]+)(?=([bcdfghjklmnpqrstvwxyz]*))/g;
var s = 'alliibaba';
var m;

do {
    m = re.exec(s);
    if (m)
} while (m);


Note that variable-width lookbehind patterns are supported only by a limited number of browsers such as Chrome and Chromium-based browsers, so regex may not be the ideal tool for a widely compatible solution.