EDIT: I should have made a little bit more research before asking. Anyway here is the solution in case someone else needs the same thing:
If I am not wrong,
[-] : means to replace a hyphen
[-]+ : means to replace one or more hyphens (-, --, ---)
/[-]+/g : means to replace multiple occurrences of one or more hyphens as in my sample string above.
Thank you, Wolf, just saw your post after posting mine May I ask what does "i" do? Your code also works without "i".