I know there are similar threads on this, but most of them only involve ignoring spaces.
I have to write an app using some poorly written data sheets, so often I have to compare things like this: Packs, packs, Pack(s), pack(s), pack
These should all be considered equal, as they are all a pack. However, none of the people who made these data sheets communicated with each other so now I get to deal with it.
How can I compare strings while ignoring parentheses, spaces, the 's' character, and also making sure everything is lowercase before comparison?
All I have right now is this:
private boolean sCompare(String s1, String s2)
{
return s1.equalsIgnoreCase(s2)
}
Obviously it isn't much and doesn't do anything other than directly compare two lowercase strings, but I'm not sure the proper approach to get the results I need.
The new comparison function should return true for the examples above, and false when comparing things like: Pack(s) and Case(s), Packs and Case(s), etc.
EDIT Using help from the best answer, I've created a function that suits my needs
private boolean sCompare(String s1, String s2)
{
String rx = "[\\se(s)|s$]";
return (s1.toLowerCase().replaceAll(rx,"")).equals(s2.toLowerCase().replaceAll(rx,""));
}