-6

Possible Duplicate:
replace all occurrences in a string

I found this question/answer:

Use JavaScript regex to replace numerical HTML entities with their actual characters

I just need to replace the one entity though. How can I match that specific pattern with a regex?

I don't know much about regex so I've done this:

.replace('–', '–')

But it obviously only replaces the first instance.

Thanks,

Thomas

1
  • 3
    What have you tried? (-1. Try something. Show what was tried and how it did/didn't work.) If you you need to replace one, no need for the function replacement. Commented May 6, 2012 at 17:56

2 Answers 2

4

The replace method only replaces the first occurance when you are using a string. Use a regular expression, so that you can specify the global flag g:

.replace(/–/g, '–')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I accepted @Esailija answer as it was 1 min before yours.
1
.replace(/–/g, '–')

the g flag means global so it replaces all instances.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.