开发者

How can I replace() multiple characters at once?

开发者 https://www.devze.com 2023-04-03 19:32 出处:网络
I have an string like this: var set = \'ñ This is a Test Ñ\'; What I need to do is replace ñ and Ñ with n. I tried:

I have an string like this:

var set = 'ñ This is a Test Ñ';

What I need to do is replace ñ and Ñ with n. I tried:

开发者_运维技巧set.replace(/\u00F1/g, 'n');

but it only replaces the ñ.


I think there is a cleaner way to write this, but this should work. The | acts as an OR in regex.

a = set.replace(/\u00F1|\u00D1/g, 'n');
0

精彩评论

暂无评论...
验证码 换一张
取 消