I have a value like below in a variable:
var str = BT 2,100,000.00
I want to remove characters till semicolon and keeps everything after semicolon. So final output will be like below :
Output : 2,100,000.00
Can someone please help?
You can use regex and capturing groups:
const str = "BT 2,100,000.00";
const regexExp = /(.*);(.+)/;
const match = str.match(regexExp);
console.log(match[2]);
If you don't need the left part of your string you can remove the parenthesis from the first part of the regex.
const str = "BT 2,100,000.00";
const regexExp = /.*;(.+)/;
const match = str.match(regexExp);
console.log(match[1]);
If you want to modify the string you can use the replace function with a regex.
const str = "BT 2,100,000.00".replace(/.*;/,"");
console.log(str);
You can use String.prototype.substring
str.substring(str.lastIndexOf(";")+1, str.length)
Using Array.prototype.split is one way:
const str = "BT 2,100,000.00";
const number = str.split(';')[1];
console.log(number);
You can also use destructuring:
const str = "BT 2,100,000.00";
const [trash, number] = str.split(';');
console.log(number);