I have set up input fields for users to enter tags.
For example, if a user enters "xyz_DTL_D, John_D
" it will be stored in the tagArr[]
array.
My goal is to replace the input "_D
" with an empty string. So I created the following code:
var dailycheck = "_D";
for(var i = 0; i < tagArr.length; i++) {
if(tagArr[i].indexOf(dailycheck) !== -1){
var str = tagArr[i].toString();
var finalTag =res.replace("_D" ,"");
$scope.tag[i] = finalTag;
}
}
The issue is that it replaces "_DTL
" as well, which is not the desired outcome.
Desired output: XYZ_DTL , John
Current output: XYZTL_D , John
Is there a way to only replace the expression "_D
" and not part of a word starting with _D
for all instances?
Any suggestions are appreciated.
Thank you