fork download
  1. import re
  2.  
  3. def wrapper_huepper(new_str, n):
  4. counter = 0
  5. n = n
  6. new_str = new_str
  7. def replace(matchobj):
  8. nonlocal counter
  9. counter = counter + 1
  10. if counter == n:
  11. return new_str
  12. return matchobj.group(0)
  13. return replace
  14.  
  15. test_str = 'aBaBaBaBaB'
  16. w1 = '********'
  17. replace = wrapper_huepper(w1, 3)
  18. x = re.sub(r"(?<=\w)[A-Z]", replace, test_str)
  19. print(x)
  20.  
Success #stdin #stdout 0.03s 9492KB
stdin
Standard input is empty
stdout
aBaBa********aBaB