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

I have an string like this:var set = 'ñ This is a Test Ñ';What I need to do is replace ñ and

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744097977a4558295.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信