admin 管理员组

文章数量: 1086019

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

本文标签: javascriptHow can I replace() multiple characters at onceStack Overflow