I was looking for a trim function in JavaScript which doesn't exist and some code on Googling suggests that use:
function trimStr(str) {
return str.replace(/^\s+|\s+$/g, '');
}
I want to know how str.replace(/^\s+|\s+$/g, '')
works. I understand that this is some form of regular expression but dont know what it is doing.