fork download
  1. import re
  2. content = '''
  3. Blah - blah \n blah * blah + blah.
  4. '''
  5.  
  6. regex = r'[\n+*/-]'
  7. my_dict = { '+': 'rep1', '\n': 'rep2'}
  8. new_content = re.sub(regex, lambda m: my_dict.get(m.group(),""), content)
  9. print(new_content)
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
rep2Blah  blah rep2 blah  blah rep1 blah.rep2