How to substitute a repeating character with the same number of a different character in regex python? [duplicate]

  python-3.x, regex

Assume there’s a string "striiiiiing". I need to replace the 'i's with '*'s like 'str******ng'. The number of '*' must be same as 'i'. However, if the number of 'i' is less than 3 then there is no need to make any changes.
How can we do that using regex?

Source: Python-3x Questions

LEAVE A COMMENT