I'm trying to find if the last word of the string is followed by a space or a special char, and if yes return the string without this space/special char
For example :
"do you love dogs ?" ==> return "do you love dogs" "i love my dog " (space after dog) ==> return "i love my dog" "do you love dogs?" ==> return "do you love dogs"
So far I tried :
It works in the last example but not in the first two (it keeps the space of the second example) and I don't know how to deal with it.
EDIT : the special chars are : '.', '!', '?', '(', '[',',' at first then every other non numeric/alphabetical except those