最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I replace() multiple characters at once? - Stack Overflow

programmeradmin6浏览0评论

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 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 ñ.

Share Improve this question edited Sep 10, 2011 at 19:27 eldarerathis 36.3k10 gold badges92 silver badges94 bronze badges asked Sep 10, 2011 at 18:00 Jonathan EdgardoJonathan Edgardo 5131 gold badge9 silver badges23 bronze badges 1
  • The variable Set is obtained from a input Value, I know u00F1 = ñ And u00D1 = Ñ – Jonathan Edgardo Commented Sep 10, 2011 at 18:05
Add a ment  | 

1 Answer 1

Reset to default 6

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)

  1. 暂无评论