I need reg expression.
I do calculator, and this string appear at my view side of app.
How to get this “111+22-33*4” from this “111+++22-33*****4”
Or another example
How to get “22243+11” from “22243++++11”
“565656565656565656565”
I need reg expression.
I do calculator, and this string appear at my view side of app.
How to get this “111+22-33*4” from this “111+++22-33*****4”
Or another example
How to get “22243+11” from “22243++++11”
“565656565656565656565”
2
Answers
Here’s how to do this with a simple loop.
Analysis:
([-/*+])
– capture your target character to replace into a capture group1+
– match any number of repeating captured character/g
– global replace$1
– replace with 1 captured characterAn
Array::reduce()
one-liner:And a benchmark: