0

I have a few strings for example

-11 -11 --11
-22 ----22 -22

I need to replace any count of - coming one by one to single -. After replacing i should get

-11 -11 -11
-22 -22 -22

Thanks!

Sasha Kos
  • 2,480
  • 2
  • 22
  • 37

1 Answers1

3

Just use replace on string with regex that matches more than one number of occurences of '-' with a single '-'

my_str = my_str.replace(/-{2,}/g, '-')
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55