I need to replace [link]0[/link] with <a href=...
Now, the links are saved in an array links and the number inside [link][/link] is the pointer to links index.
I am trying to do next:
txt.replace( /\[link\](\d+)\[\/link\]/ , "<a href='" + links[ THE_INDEX ][ 0 ] + "' target='_blank'>" + ( links[ THE_INDEX ][ 1 ] || links[ THE_INDEX ][ 0 ] ) + "</a>" );
but I don't know, how to pass the saved value. Could you help me solve it?
P.S. I know I could make loop and use the exec() to save value and pass it, but I want to know, is it possible to do it like I sayd above.
For a more simple example of expectation
my_array = [ "data1", "data2", "data3" ];
"xxx1xxx".replace( /xxx(\d+)xxx/, "my_data=" + my_array[ THE_MATCH ] ); // should be "my_data=data1"
"xxx3xxx".replace( /xxx(\d+)xxx/, "my_data=" + my_array[ THE_MATCH ] ); // should be "my_data=data3"
Where THE_MATCH is taken from the regex match.