I can't solve one problem.
There is a string in which in some places there are hex codes, codes can be many. I need to write a function that can return a string with changed codes. What was I trying to do:
function test(i,color){
let str = "Lorem ipsum #1385ff dolor sit amet, #1385ff consectetur adipisicing #1385ff elit. #333 Neque , est, voluptatum,#333";
str = str.replace(str.match(/#[0-9a-f]{6}|#[0-9a-f]{3}/gi)[i],color)
return str
}
console.log(test(2,"#000"))
What I expected to get:
Lorem ipsum #1385ff dolor sit amet, #1385ff consectetur adipisicing #000 elit. #1385ff Neque quibusdam, est, voluptatum,#333333 aperia
What I got:
Lorem ipsum #000 dolor sit amet, #1385ff consectetur adipisicing #1385ff elit. #1385ff Neque , est, voluptatum,#333333
I will be very grateful for your help :)