Answer the question
In order to leave comments, you need to log in
How to replace all single characters with some other one?
For example, replace all 1s with 2. But if there are two 1s nearby, then do not replace them.
We try:
'aaa11aaaa1bbb1ccc1d1eeee'.replace(/([^1])1([^1])/g,'$12$2')
"aaa11aaaa2bbb2ccc2d1eeee"
Answer the question
In order to leave comments, you need to log in
Something like that:
'aaa11aaaa1bbb1ccc1d1eeee'.replace(/(\D|^)([1]{1})((?=[a-zA-Z]|$))/g, '$12$3')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question