Replace Character with Count

Viewed 878

Goal: Replace consecutive asterisks with the count of them surrounded by the sup tag.

Input

Hello, my name is Chris Happy*. My profile picture is a happy face.**

*: It's not my actual name, but a nickname.
**: Well, my "last name" is happy, so I think it's fitting.

Output

Hello, my name is Chris Happy<sup>1</sup>. My profile picture is a happy face.<sup>2</sup>

<sup>1</sup>: It's not my actual name, but a nickname.
<sup>2</sup>: Well, my "last name" is happy, so I think it's fitting.

How could I efficiently accomplish this?

3 Answers
Related