【发布时间】:2020-07-16 22:14:51
【问题描述】:
鉴于我有一个故事。故事由文字组成。我需要构造一个正则表达式来计算故事中每个单词的音节数。
我尝试构造一个满足以下条件的正则表达式:
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
IF word contains only a lone 'e' at the end of a word
AND word does not contain other vowel characters
THEN match the lone 'e'
预期输出:
计算每个单词的匹配结果应该是:
3 个音节表示 aerospace
1 音节 she
总共个4个音节。
我能够构造 (?(?=([a-zA-Z]+e))(?=([aeiouy]))),但如果可能的话,我需要你的帮助才能在一个表达式中完成它。
【问题讨论】:
-
为什么要匹配它们?您是在提取、计数、替换吗?你有一个
aerospace she字符串。预期的输出是什么? -
@WiktorStribiżew 我编辑了我的问题。