[英]regex expression to remove eed from string
I am trying to replace 'eed' and 'eedly' with 'ee'
from words where there is a vowel before either term ('eed' or 'eedly')
appears. 我试图
'eed' and 'eedly' with 'ee'
替换'eed' and 'eedly' with 'ee'
来自有元音的单词,然后出现任意一个词('eed' or 'eedly')
。
So for example, the word indeed
would become indee
because there is a vowel ('i') that happens before the 'eed'. 因此,例如,单词
indeed
会变为不indee
因为有一个元音('i')发生在'eed'之前。 On the other hand the word 'feed'
would not change because there is no vowel before the suffix 'eed'
. 另一方面,
'feed'
这个词不会改变,因为在后缀'eed'
之前没有元音。
I have this regex: (?i)([aeiou]([aeiou])*[e{2}][d]|[dly]\\\\b)
You can see what is happening with this here . 我有这个正则表达式:(
(?i)([aeiou]([aeiou])*[e{2}][d]|[dly]\\\\b)
你可以看到这里发生了什么。
As you can see, this is correctly identifying words that end with 'eed'
, but it is not correctly identifying 'eedly'
. 正如您所看到的,这是正确识别以
'eed'
结尾的单词,但它没有正确识别'eedly'
。
Also, when it does the replace, it is replacing all words that end with 'eed'
, even words like feed
which it should not remove the eed
此外,当它进行替换时,它将替换所有以
'eed'
结尾的单词,甚至是像feed
这样的单词,它不应该删除eed
What should I be considering here in order to make it correctly identify the words based on the rules I specified? 我应该在这里考虑什么,以便根据我指定的规则正确识别单词?
You can use: 您可以使用:
str = str.replaceAll("(?i)\\b(\\w*?[aeiou]\\w*)eed(?:ly)?", "$1ee");
\\\\b(\\\\w*?[aeiou]\\\\w*)
before eed
or eedly
makes sure there is at least one vowel in the same word before this. \\\\b(\\\\w*?[aeiou]\\\\w*)
在eed
或eedly
之前确保在此之前同一个单词中至少有一个元音。
To expedite this regex you can use negated expression regex: 要加速这个正则表达式,你可以使用否定表达式正则表达式:
\\b([^\\Waeiou]*[aeiou]\\w*)eed(?:ly)?
RegEx Breakup: RegEx分手:
\\b # word boundary
( # start captured group #`
[^\\Waeiou]* # match 0 or more of non-vowel and non-word characters
[aeiou] # match one vowel
\\w* # followed by 0 or more word characters
) # end captured group #`
eed # followed by literal "eed"
(?: # start non-capturing group
ly # match literal "ly"
)? # end non-capturing group, ? makes it optional
Replacement is: 更换是:
"$1ee" which means back reference to captured group #1 followed by "ee"
find dly before finding d. 在找到d之前找到dly。 otherwise your regex evaluation stops after finding eed.
否则你的正则表达式评估在找到eed后停止。
(?i)([aeiou]([aeiou])*[e{2}](dly|d))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.