Hello Helpers ,
I have a regExp pattern to define, and one array to crawl with its content as substitute for all slot found.
I am approaching a good solution , but am not enough expert at it.
My goal is to use 2 dimensional Array, and wrap it by the pattern/scheme from 'pattern var'.
I am stuck at 'having the good' regexp , and the relevant use of the 'replace' function.
the regexp pattern require to pick all '%integers' , and replace them by the good feed[index]
thanks in advance
I have a regExp pattern to define, and one array to crawl with its content as substitute for all slot found.
I am approaching a good solution , but am not enough expert at it.
JavaScript:
<script>
var list = [["a","b"],["c","d"],["e","f"]] ; // content Array, at goal it could have 10 vars in each sub_arrays
var pattern = "%1 %1 %2 %1" ; // string target, requiring all replaces for each %var
function build(feed,pattern){
outraw = "" ;
for(let i=0;i < feed.length;i++){
// below : my try about setting the RegExp pattern
outraw += pattern.replace( new RegExp(["%1","%2"],"i") , feed[i][0] , feed[i][1] ) ;
outraw += "<br>" ;
}
alert(outraw);
document.body.innerHTML += outraw ;
outraw = null;
}
</script>
</head>
<body onload="build(list,pattern);">
My goal is to use 2 dimensional Array, and wrap it by the pattern/scheme from 'pattern var'.
I am stuck at 'having the good' regexp , and the relevant use of the 'replace' function.
the regexp pattern require to pick all '%integers' , and replace them by the good feed[index]
thanks in advance