Hi all
This sounds pretty simple, but I'm trying to create a regular expression whereby, for any word, the matcher will find all instances of that word OR it's plural.
Now, if it were just adding +s, I know I could do
Pattern.compile("\b\Q" + word + "\Es?\b");
// note, this forum seems to spaz when I use double-slashes, so I omitted them
However, if it ends in a "y", like "try", I need to find words that end in "ies", like "tries".
At first I thought of making two cases in the pattern, one as above, and one were the last letter is subtracted and you check for (y|ies). HOWEVER, without first knowing if the word ends in a "y", it could take "do" and change it into "dies", and then mistakenly find it.
Of course, I COULD have a whole bunch possible patterns seperated by a bunch of IF-THENs... "if it ends in a y, Pattern pattern = Patern.compile(...."
... but this doesn't seem very elegant.
So, how can I create a pattern that will check for "ies" ONLY if the word ends in "y" (and +"es" if it ends in an "s" and so on...)?
Thanks!
Tim