fork download
  1. import re
  2. def repl(m):
  3. return "{0}{1}{2}".format(m.group(1), re.sub(r'\w+', 'Aa', m.group(2)), m.group(3))
  4. string = "one,two,three,"
  5. print(re.sub(r'(,?)(.*?)(,+)',repl, string))
  6. print(re.sub(r'(,?)(.*?)(,+)', lambda m: "{0}{1}{2}".format(m.group(1), re.sub(r'\w+', 'Aa', m.group(2)), m.group(3)), string))
  7.  
Success #stdin #stdout 0.01s 9024KB
stdin
Standard input is empty
stdout
Aa,Aa,Aa,
Aa,Aa,Aa,