Relative newcomer to Javascript and looking for a way to remove the last character of a string if it is a colon.
I know myString = myString.replace('/^\\:/'); will work for the start of the line but not sure how to swap in the $ character to change to the end of a line… can anybody correct it?
Thanks
The regular expression literal (
/.../) should not be in a string. Correcting your code for removing the colon at the beginning of the string, you get:To match the colon at the end of the string, put
$after the colon instead of^before it:You can also do it using plain string operations: