Editor

Mask an Email Address

#222 · Strings · Beginner · 30 XP · about 5 min

Account pages often show an email address partly hidden, so its owner can recognise it while a stranger looking at the screen cannot read it. Write mask_email(email) that returns the address with its name part (everything before the @) masked like this:

  • 3 or more characters: keep the first and the last character and replace every character between them with *.
  • 2 characters: keep the first character and replace the second with *.
  • 1 character: replace it with *.

The @ and everything after it stay exactly as they are.

Examples

mask_email('jane.doe@mail.com')  # returns 'j******e@mail.com'
mask_email('sam@home.net')       # returns 's*m@home.net'
mask_email('bo@site.org')        # returns 'b*@site.org'
mask_email('x@y.io')             # returns '*@y.io'

Note

Every address contains exactly one @, with at least one character on each side of it.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.