Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Last active September 24, 2019 01:44
Show Gist options
  • Save cuylerstuwe/0c583a3027fb52e2a9bc622bc226c824 to your computer and use it in GitHub Desktop.
Save cuylerstuwe/0c583a3027fb52e2a9bc622bc226c824 to your computer and use it in GitHub Desktop.
const maskExceptLastThreeChars = str => (
str.replace(
/(?=.{4,})(.+)(.{3,}$)/,
(_, ...args) => "*".repeat(args[0].length) + args[1]
)
);
@cuylerstuwe
Copy link
Author

cuylerstuwe commented Sep 24, 2019

Solution for this Facebook post:

hi,i don't know how can i mask(change to star) a first all characters and hold last 3 characters, i don't want use for loop,have any idea is use replace to do that
for example:
123@email.com change to **********com
12345@email.com change to ************com
[...]
very crazy,but its true,i just want a simple
let email = ys@gmail.com;
let emailed = email..replace(/[^]/, '*');
but next, i don't know how can i do next step 😂
how any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment