I get back a histogram array from Photoshop as a string
var rArray = activeDocument.channels["Red"].histogram.toString()
For those of you without Photoshop, just ignore that detail as it’ll be an array something like
66500,0,0,0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0...
0,0,0,0,0,0,0,0,750,0,0,0,0,0,0,0,0,0,0...
Currently I’ve got a function to loop over the (string as an) array and remove any zero values. However, I’m sure it can be done with a regex. Only I’m picking up one of the zeros of of the number I want to keep.
.replace(/(,0)/g,"")
only that returns
665010000
75
instead of
66500
750
The expected output is to eliminate all zeros
66500,10000
750
See it here on regex101
I’m pretty sure this can me done as regex only, I don’t know how to specify "0," OR "0$" zero AND a comma OR zero and ENDSTRING literally.
2
Answers
The pattern /^0|,0/g should do the trick.
check here:
regexr.com/5akbq
You can use
See the regex demo
Details
^(?:0,)+
– one or more occurrences of0,
substring from the string start|
– or(?:,0)+$
– one or more occurrences of,0
substring till the string end|
– orb0,
– a word boundary followed with0,
substring.