正则表达式匹配顺序

编程入门 行业动态 更新时间:2024-10-12 03:22:35
本文介绍了正则表达式匹配顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题很简单,假设我想用一个单词来匹配元音,但是我想按照出现的特定顺序来匹配它们,例如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.)

更多推荐

正则表达式匹配顺序

本文发布于:2023-11-02 18:21:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!