fork download
  1. import re
  2. new_ = {
  3. '&&':'and',
  4. '||':'or'
  5. }
  6. inpStr = "good && toast&&guest &fast& slow||wind ||old|| new || very good"
  7. replDictRe = re.compile( r'(?<!\S)(?:{})(?!\S)'.format('|'.join(map(re.escape, new_.keys()))) )
  8. print(replDictRe.pattern)
  9. oidDesStr = replDictRe.sub(lambda mo:new_.get(mo.group(),mo.group()), inpStr)
  10. print(oidDesStr)
Success #stdin #stdout 0.02s 9552KB
stdin
Standard input is empty
stdout
(?<!\S)(?:\&\&|\|\|)(?!\S)
good and toast&&guest &fast& slow||wind ||old|| new or very good