I am using below code to find all matches of the given regular expression and then I replace it with some other string.
The problem is the new string replacing the old one contains the same text with some added instructions.
Now if there is another match which is exactly same as the previous one then the replace() method change the first occurrence.
Example: If I have a string: "I am looking for #12 and #3 but if I am asked to choose the best #12 would be the winner". Here #12 comes twice.
Using match() method I get an array containing #12, #3 and #12, provided regular expression /[#]{1}\d{1,4}/g.
Now if I replace #12 with <a href="bb.htm">#12</a> then using my code I am unable to replace second occurrence of #12.
Here is the code:
The first occurrence of #12 becomes an anchor but second occurrence never changes.