0

I have a requirement to remove duplicate hyphens or simply remove them if they are not the first character on the string. I would like to use a regular expression 'replace' in Java script. I have fought with it for several hours. When I think I have it, in the end all hyphens are removed. Even the first one. Below is an example of the request.

Example: 1a-1-1 Result: 1a11 Example: -1-1b-1- Result: -11b1 Example: ---1c11- Result: -1c11

Thrive
  • 1

1 Answers1

0

Use line start, it'll take only first hyphen.

^-
Raymond Reddington
  • 1,709
  • 1
  • 13
  • 21
  • Zaven, Thanks for the response. I want to keep 'only' the hyphen in position 1 if it exists and strip any other hyphens if they are entered. If there is not a hyphen in the position 1 then strip them all. It is not a duplicate. Their example uses a look-behind. I do not believe JavaScript supports look-behind assertions. – Thrive Feb 25 '20 at 15:53