开发者

Regex vowels in order but not all vowels?

开发者 https://www.devze.com 2023-03-14 12:55 出处:网络
I know there are similar questions, however the last question only stated if a word has all of the vowels in the word.What I am trying to do is find if a word has its vowels in alphabetical order.For

I know there are similar questions, however the last question only stated if a word has all of the vowels in the word. What I am trying to do is find if a word has its vowels in alphabetical order. For example the words: almost, various, etc.

I have tried many different solutions however I cannot get to this work.

Things like:

(a[^eiou]*)?(e[^aiou]*)?(i[^aeou]*)?(o[^aeio]*u)?

and

a[^eiou]*e[^aiou]*i[^aeou]*o[^aeio]*u

but these do n开发者_如何学Goot work.


Your first try is not too far, try this:

\b[^aeiou]*(?:a[^eiou]*)?(?:e[^aiou]*)?(?:i[^aeou]*)?(?:o[^aeiu]*)?u?[^aeio]*\b

See it here on Regexr.

I added:

\b word boundaries to ensure that the complete word is matched

[^aeiou]* at the beginning to match non vowels before the first "a"

(?:o[^aeio]*)?u? changed the last part a bit to make the "o" optional


How about \b[^aeiou]*a*[^eiou]*e*[^aiou]*i*[^aeou]o*[^aeiu]*u*[^aeio]*\b.


Here's my bid:

^[b-df-hj-np-tv-z]*?(?:a[b-df-hj-np-tv-z]*?)?(?:e[b-df-hj-np-tv-z]*?)?(?:i[b-df-hj-np-tv-z]*?)?(?:o[b-df-hj-np-tv-z]*?)?(?:u[b-df-hj-np-tv-z]*?)?$

Can also bind by word separators (\b) but seems to pass my testing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号