Capturing consecutive non-alphanumeric characters in a string in a single group
javascript, regex
Solution
Use `+` to match 1 or more repetitions:
> "Querty(&)keypad".replace(/[^A-Za-z0-9]+/g, "-")
"Querty-keypad"
Problem
I want to replace all special characters in a string with dashes. I use the following regex to replace the characters. ``` var x = "Querty(&)keypad"; alert(x.replace(/[^A-Za-z0-9]/g, "-")); ``` However, this causes each character to be replaced by a dash, rather than replacing consecutive characters with a single dash. This examples gives me the output `Querty---keypad`. My desired output is `Querty-keypad`. You can see the issue in this jsfiddle.