I have a string that contains Chinese characters, English and numbers. I want to replace numbers and English with *. How do I do this? Usually it is a simple replacement. This requires regular expressions
4 answers
Loop it over and judge the ASCII code directly. Use c syntax to compare and change characters one by one
Isn’t this okay?
var str = '123你好呀hehe';
console.log(str.replace(/\w/g, '*')); NSString *content = @"哈哈哈哈test哈t123哈哈哈哈";
NSLog(@"替换前--- %@",content);
NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z0-9]" options:0 error:nil];
content = [regularExpression stringByReplacingMatchesInString:content options:0 range:NSMakeRange(0, content.length) withTemplate:@"*"];
NSLog(@"替换后--- %@",content);

Hot tools Tags
Hot Questions
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
20417
7
13577
4






