My problem start with like-
var str='0|31|2|03|.....|4|2007'
str=str.replace(/[^|]\d*[^|]/,'5');
so the output becomes like:”0|5|2|03|….|4|2007″ so it replaces 31->5
But this doesn’t work for replacing other segments when i change code like this:
str=str.replace(/[^|]{2}\d*[^|]/,'6');
doesn’t change 2->6.
What actually i am missing here.Any help?
Here is a specific regex solution which replaces the number following the first
|pipe symbol with the number5:If you want to replace the digits following the third
|, simply change the{1}portion of the regex to{3}Here is a generalized function that will replace any given number slot (zero-based index), with a specified new number: