I'm pretty new to regex but I'm trying to use a variable inside my match.
So I have a string that is "Total: $168" I'm trying to get the number amount, 168.
So I have this:
totalCost = totalCost.match(/[^Total: $]*$/);
when i echo that out I get 168. This is working, this is what I want.
But now I want to take it one step further and want to make "Total: $" a variable so I can easily set it and make this modular.
So I did
var stringToSearch = 'Total: $';
and then did
totalCost = totalCost.match(/[^stringToSearch]*$/);
I do a console log of:
console.log(totalCost+" || "+stringToSearch );
and I get:
l: $168 || Total: $
Why when I make this variable it behaves all weird?