Reputation: 1543
function getStatementValue(view, statement){ // vars "@extends('parentview') ", 'extends'
var parentname = "";
view.replace(new RegExp(/\B@\w+\('([^(')\W]+)'\)\s/, 'm'), function(occurance){
parentname = occurance.replace('@' + statement + '(\'', '')
.replace('\')', "");
console.log(parentname) // parentview
console.log(parentname + 'test') // testntview <- unexpected result
});
return parentname;
}
I've got no clue to how that result is appearing.
when I add the string as shown in console.log, it replaces the string from the beginning, almost like it's re-assigning the memory space. Is this supposed to be happening? How do I return the correct parentviewtest
result?
Upvotes: 1
Views: 72
Reputation: 1543
parentname = occurance.replace('@' + statement + '(\'', '')
.replace('\')', "").trim();
Solved it by adding a .trim()
to the string modification. My input included invisible \r and \n characters that I was unaware of.
Thanks to @JaromandaX for spotting that out
Upvotes: 1