Regular expression for three different vowels in a row

I am trying to write a regular expression that matches 3 or more different vowels in a string. I understand to write a regex search of 3 identical vowels.

/([aeuioy])\\1{2,}/ 

But about 3 different ... any thoughts ..

Please help me solve this problem! In fact, there are no thoughts in my head.

+6
source share
4 answers

Look for 3 consecutive vowels. Capture the first in the group. After the first, check to see if it is again No. 1 with a negative Lookahead. After passing this test, take the next character. Then use two negative Lookaheads, one to check if it is No. 1, and the other if it is not # 2.

The last step can be OR 'in one look.

 (?=[aeouiy]{3})(.)(?!\1)(.)(?!\1|\2). 

You do not need a test for the last character. The first Lookahead provides him with one of aeouiy ; third, negative, lookahead ensures that it is not character # 1 or character # 2.

+11
source

Not that this is necessarily the most practical option, but so far this is the only "regular" regular expression:

 (iea|oea|uea|yea|eia|oia|uia|yia|eoa|ioa|uoa|yoa|eua|iua|oua|yua|eya|iya|oya|uya|iae|oae|uae|yae|aie|oie|uie|yie|aoe|ioe|uoe|yoe|aue|iue|oue|yue|aye|iye|oye|uye|eai|oai|uai|yai|aei|oei|uei|yei|aoi|eoi|uoi|yoi|aui|eui|oui|yui|ayi|eyi|oyi|uyi|eao|iao|uao|yao|aeo|ieo|ueo|yeo|aio|eio|uio|yio|auo|euo|iuo|yuo|ayo|eyo|iyo|uyo|eau|iau|oau|yau|aeu|ieu|oeu|yeu|aiu|eiu|oiu|yiu|aou|eou|iou|you|ayu|eyu|iyu|oyu|eay|iay|oay|uay|aey|iey|oey|uey|aiy|eiy|oiy|uiy|aoy|eoy|ioy|uoy|auy|euy|iuy|ouy) 
+5
source

You can use this lookahead regex:

 ^(?:[^aeiou]*([aeiou])(?!.*?\1)){3} 

RegEx Demo

Update: If the OP is looking for at least three consecutive different vowels on each line , use this simpler version above regex:

 (?:([aeiou])(?!.{1,2}\1)){3} 

New RegEx Version

+3
source

Any thing you want is a permutation between vowels, so you can use this:

 (?=[aeouiy]{3}$)(?!.*(.).*\1).*$ 

(?!.*(.).*\1) intended so that you cannot combine a repeating character!

+1
source

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


All Articles