正则表达式匹配顺序 [英] Regex match ordering
问题描述
我的问题很简单,假设我想用一个单词来匹配元音,但是我想按照出现的特定顺序来匹配它们,例如a,e,i,o,u.我将如何去做?
My question is simple suppose I would like to match the vowels in a word, but I would like to match them in a specific order as the appear such as a, e, i, o, u. How would I go about doing this?
推荐答案
因此,您要查找 a
后跟一些字符,然后是 e
后跟一些字符,等等吗?
So you're looking for a
followed by some characters, then e
followed by some characters, and so forth?
换句话说,先 a
,然后是不是 e
的内容,然后是 e
.然后是不是 i
的东西,然后是 i
的东西.然后是不是 o
而不是 o
的东西.最后是不是 u
的东西,最后是 u
的东西.
In other words, a
followed by stuff that isn't e
, then e
. Then stuff that isn't i
then i
. Then stuff that isn't o
then o
. And finally stuff that isn't u
and lastly a u
.
在正则表达式中,这是 a [^ e] * e [^ i] * i [^ o] * o [^ u] * u
In regexp terms, that's a[^e]*e[^i]*i[^o]*o[^u]*u
(您可以使用.*?
来解决,但是当您可以更精确地定义您的意思时,为什么要这么做呢?)
(You could get by with a .*?
but why do that when you can more precisely define what you mean.)
这篇关于正则表达式匹配顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!