0

Are there any alternatives that are similar to .replace() but that allow you to pass more than one old substring to be replaced?

I have a function with which I pass video titles so that specific characters can be removed (because the API I'm passing the videos too has bugs that don't allow certain characters):

def videoNameExists(vidName):
    vidName = vidName.encode("utf-8")
    bugFixVidName = vidName.replace(":", "")
    search_url ='https://api.brightcove.com/services/library?command=search_videos&video_fields=name&page_number=0&get_item_count=true&token=kwSt2FKpMowoIdoOAvKj&any=%22{}%22'.format(bugFixVidName)

Right now, it's eliminating ":" from any video titles with vidName.replace(":", "") but I also would like to replace "|" when that occurs in the name string sorted in the vidName variable. Is there an alternative to .replace() that would allow me to replace more than one substring at a time?

2 Answers 2

2
>>> s = "a:b|c"
>>> s.translate(None, ":|")
'abc'
Sign up to request clarification or add additional context in comments.

Comments

1

You may use re.sub

import re
re.sub(r'[:|]', "", vidName)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.