If I have a string, for example, “ASDFBOB DESUDESUBOBADSF”, how can I remove all mentions of “bob” turning the line into “ASDF DESUDESUADSF”? It would be a great help, thanks!
Share
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.
Use
str.replacewith a replacement of the empty string:By default, that replaces all instances; if you only want to replace 1 (or up to N) instances, pass that in as the third parameter, e.g.
x.replace('BOB', '', 1).If you need more powerful replacement functionality, such as case insensitivity or regular expressions, use
re.subinstead.