Java 如何用正则表达式确定单词中的音节

Java 如何用正则表达式确定单词中的音节,java,regex,Java,Regex,假设我有一个故事。这个故事由文字组成。我需要构造一个正则表达式来计算故事中每个单词的音节数 我尝试构造一个正则表达式,其中满足以下条件: IF word ends with character 'e' AND word also contains at least one of the vowel characters 'a'|'e'|'i'|'o'|'u'|'y' THEN do not match 'e' at the end of word BUT match all the other

假设我有一个故事。这个故事由文字组成。我需要构造一个正则表达式来计算故事中每个单词的音节数

我尝试构造一个正则表达式,其中满足以下条件:

IF word ends with character 'e'
AND word also contains at least one of the vowel characters 'a'|'e'|'i'|'o'|'u'|'y'
THEN do not match 'e' at the end of word
BUT match all the other vowels in word
预期产出:

计算每个单词的匹配项应得出:

3ae的音节rospace

she的1音节

共有4个音节


我能够构造
(?(?=([a-zA-Z]+e))(?=([aeiouy])
,但是如果可能的话,我需要您的帮助,以在单个表达式中完成它。

在阅读了大量关于Regex和Regex条件的使用之后。默认情况下,Java正则表达式包不支持条件。(在这里找到答案:)

因此,最终构造了一个没有if-else-then条件的正则表达式

([aeiouyAEIOUY]+[^e.\s])|([aiouyAEIOUY]+\b)|(\b[^aeiouy0-9.']+e\b)
()

欢迎改进


谢谢

为什么要匹配它们?你在提取、计数、替换吗?您有一个
字符串。预期的结果是什么?@WiktorStribiżew我编辑了我的问题。
([aeiouyAEIOUY]+[^e.\s])|([aiouyAEIOUY]+\b)|(\b[^aeiouy0-9.']+e\b)