简体   繁体   中英

How can I replace() multiple characters at once?

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');

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