fork download
  1. import re
  2. inputString = "I want to remove <code>tag with space</code> not sole <code>word</code>"
  3. outputString = re.sub("<code>(.+?)</code>", lambda m: " " if " " in m.group(1) else m.group(), inputString, flags=re.S)
  4. print(outputString)
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
I want to remove   not sole <code>word</code>