[英]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我想做的是能够屏蔽第一个字母,并且除了邮件之外的所有内容都保留在 aterisks 中,例如:*****@email.com
Try regex /.+?(?=@)/g
试试正则表达式
/.+?(?=@)/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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.