I know how to make string replacements in Python but I need a way to replace only if the sequence is located at the end of the word.
For example:
Rule: at → ate
So cat is changed to cate.
But attorney stays unchanged.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A regex can do that with ease:
Result:
With regexes, we can perform very complicated tasks.
For example, replacing several kinds of strings with a particular replacement for each, thanks to the use of a callback function (here named
repl, that receives catched MatchObjects)Result: