This should be very simple for someone who knows regex. I don’t need anything hardcore, just a simple altering of .replace(/[e']?s$/, ''); below
Someone else typed this code, it allows for plural endings on the ends of words in my specific situation, so if i typed “planet”, it would also match “planets”, and “planet’s”, but if I typed “hecktus”, it wont match “hecktus”, I think it’s because the word ends with an “s”, and that’s throwing it off. Is there a better way to allow for plural endings for words, that would also allow the word “hecktus” to match “hecktus”?
$.trim(inputWords[i]).replace(/[e']?s$/, '');
Plurals in English are a lot more complicated than that. Even not including irregulars, that code will not really catch a lot. You ran into one case where it fails, but there are going to be more. A single regular expression is not really something you can use to cover what you are thinking about (at least not from the looks of it). And if you are trying to detect if something is plural or singular, you are going have trouble.
Now, as for what to do with your input. I would recommend stemming things instead (unless you need to use the exact version given for some reason). A Google search prompted a JavaScript Stemming library that is listed on the Porter Stemming Algorithm page here
Update
Simple regex that will not match hecktus:
/([e']s|[^aiou]s)$/In english: Match an s if there is preceeded by an apostrophe, or e. Or match on an s that is proceeded by something other than a, i, o, or u.
Note that this will also grab the character before in the case of planets, so you can’t just use it in a replace. You can instead do: