Seems you want a simple solution that looks for s
or es
at the end of a word, and removes them.
To do that, you need to ensure that the found s
or es
is at the end of a word, i.e. at least one letter before, and no letters after. For that, use the
word boundary and B
non-word boundary patterns.
Instead of (s|es)
you should use optional e
followed by s
, i.e. e?s
data = data.replaceAll("\Be?s\b", "");
Example
String data = "The quick brown foxes jumps over the lazy dogs";
data = data.replaceAll("\Be?s\b", "");
System.out.println(data);
Output
The quick brown fox jump over the lazy dog
Notice how the flawed premise of the code (that all words ending with s
are plural words) also changes jumps
to jump
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…