The string I have is "Last Updated on November 7, 8:00 PM AST". Using regex I want to remove "AST" off of the end of it. How do I go about doing so?
Using regex, you could do this:
var string = "Last Updated on November 7, 8:00 PM AST";
var modified = string.replace(/ \w{3}$/, '');
Though, if it is always going to be the last three characters (and the space) in the string, this will probably be faster:
var modified = string.substring(0, string.length - 4);
No need regex, just get the substring up till the last index of a space character.
var s = "Last Updated on November 7, 8:00 PM AST";
s.substr(0, s.lastIndexOf(" ")) // "Last Updated on November 7, 8:00 PM"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With