简体   繁体   中英

Capture the entire text string and convert it to asterisks

I have the following code which generates a type of style that hides part of a text in asterisks.

  transform(value: string): string {
    return value 
      ? value.replace(/\B\w+@/g, (c, ) => c.split('').slice(0, -1).map(v => '*').join('') + '@') 
      : value;
  }

The result is this example image:

在此处输入图片说明

What I would like to do is to be able to mask also the first letter and that everything remains in aterisks except the mail, for example: *****@email.com

Try regex /.+?(?=@)/g

var emailRegex = /.+?(?=@)/g;
var email = 'test@email.com';
var text = email.match(emailRegex)[0];
email = email.replace(emailRegex, '*'.repeat(text.length));

Replace following

/\B\w+@/g

with just

/\w+@/g

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM