Edville
Edville

Reputation: 345

replacing several characters using javascript replace

I want to replace all the occurrences of accented characters À, Á, Â, Ã, Ä, Å with "A" using javascript replace ( For example, "ÀNÁPIÂLÃZÄ" would be rendered to "ANAPIALAZA"). I tried:

var re = /À||Á||À||Á||Â||Ã||Ä||Å/g; 
name =  name.replace(re,"A");

and

var  re = /(ÀÁÂÃÄÅ)/g;
name =  name.replace(re,"A");

I not sure how to express the desired rule in regex pattern. Thanks

Upvotes: 0

Views: 2084

Answers (2)

tckmn
tckmn

Reputation: 59273

Use [] square brackets, like this:

/[ÀÁÀÁÂÃÄÅ]/g

The problem with your first || example, by the way, is that you should only use one | in regexes.

Upvotes: 1

chrx
chrx

Reputation: 3572

Square [ ] brackets will solve your problem.

var  re = /[ÀÁÂÃÄÅ]/g;
name =  name.replace(re,"A");

Example: http://jsfiddle.net/y2a6x/

Upvotes: 1

Related Questions