Answers for "multiple replace"


multiple replace

var str = '[T] and [Z] but not [T] and [Z]';
var result = str.replace('T',' ').replace('Z','');
Posted by: Guest on May-12-2020

python .replace multiple

import re

rep = {"condition1": "", "condition2": "text"} # define desired replacements here

# use these three lines to do the replacement
rep = dict((re.escape(k), v) for k, v in rep.iteritems()) 
#Python 3 renamed dict.iteritems to dict.items so use rep.items() for latest versions
pattern = re.compile("|".join(rep.keys()))
text = pattern.sub(lambda m: rep[re.escape(], text)
Posted by: Guest on July-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language