正则表达式未产生预期输出

发布于 2024-12-18 23:36:22 字数 271 浏览 4 评论 0原文

我正在制作一个简单的正则表达式来识别第一个辅音(如果有),然后识别中间的所有元音,然后识别最后一个元音之后的下一个辅音(如果有)。

例如:

we are all morons -->> we ae al moon

我写了这个表达式,但它并不在所有情况下都有效。

请指教。

"[^aeiou]?[aeiou]+[aeiou]?"

不知道我哪里出错了。

I am making a simple regular expression to recognise first consonant(if any),then all the vowels in between and then the next consonant after the last vowel(if any).

For ex:

we are all morons -->> we ae al moon

I wrote this expression but it doesn't work in all situations.

Please advise.

"[^aeiou]?[aeiou]+[aeiou]?"

Not sure where I am getting wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玻璃人 2024-12-25 23:36:22

您需要使用非捕获组,以便匹配不会停止。现在您只匹配与您所需的输出相匹配的单词。请参阅:什么是非捕获组?问号后跟冒号 (?:) 是什么意思?
了解更多信息。

You need to use non capturing groups so the matching wont halt. Now you are matching only words that matches your desired output. see : What is a non-capturing group? What does a question mark followed by a colon (?:) mean?
for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文