Skip to content
Advertisement

How to strip a specific word from a string?

I need to strip a specific word from a string.

But I find python strip method seems can’t recognize an ordered word. The just strip off any characters passed to the parameter.

For example:

JavaScript

How could I strip a specified word with python?

Advertisement

Answer

Use str.replace.

JavaScript

Alternatively use re and use regular expressions. This will allow the removal of leading/trailing spaces.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement