I would like to perform a MySQL regular expression which will check a string for both singular and plural version of the string.
I am ignoring special characters and complex grammar rules and simply want to add or remove an 's'.
For example if the user enters 'shoes' it should return matches for both 'shoes' and 'shoe'. Conversely, if the user enters 'shoe' it should return matches for both 'shoe' and 'shoes.
I am able to optionally check against the plural version of the match as follows:
WHERE Store.tags RLIKE ('(^|,)+[[:space:]]*shoe(s)*[[:space:]]*(,|$)+')
I have been reading up about positive/negative look-ahead or look-behind and I seem to be consta开发者_StackOverflow中文版ntly chasing my tail.
Well if you're only asking about removing or adding an s ... make it simple as your requirements ...
Just check if last letter is an s.. if yes -> remove it for singular, if no, add one for plural
WHERE (a LIKE '%shoes%' OR a LIKE '%shoe%')
It's as dumb as it gets but seeing you only need to check for s .. it's good enough.
精彩评论