Skip to content
Advertisement

Javascript string-replace function ignoring hyphen

I have the following code:

JavaScript

The alert gives hello,,..there

I would expect it to give hello---,,..there as all the characters, including hyphens, are specified as exceptions in the replacement function.

What am I doing wrong?

Advertisement

Answer

Escape the hyphen:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement