1var str = '[T] and [Z] but not [T] and [Z]';
2var result = str.replace('T',' ').replace('Z','');
3console.log(result);
1import re
2
3rep = {"condition1": "", "condition2": "text"} # define desired replacements here
4
5# use these three lines to do the replacement
6rep = dict((re.escape(k), v) for k, v in rep.iteritems())
7#Python 3 renamed dict.iteritems to dict.items so use rep.items() for latest versions
8pattern = re.compile("|".join(rep.keys()))
9text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
10