0

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

4
  • 1
    square brackets; /[abc]/g means any a or b or c. Commented Apr 4, 2013 at 0:50
  • 1
    Your first attempt should have worked, except you should only have a single pipe between the characters, not two pipes. Commented Apr 4, 2013 at 0:56
  • I see. A single | gets it working. Thanks Commented Apr 4, 2013 at 1:06
  • Note that there are more than one way to render ÀÁ (not sure about other characters, but it may also applies): either a single character, or a base character plus a combining diacritics. Commented Apr 4, 2013 at 7:11

2 Answers 2

1

Square [ ] brackets will solve your problem.

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for giving that link.
1

Use [] square brackets, like this:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.