Code:
QstrVal.replace(/^\s+(.+)/, "$1"); // replace one or more SPACEs at start of string with nothing
QstrVal.replace(/(.+)\s+$/, "$1"); // replace one or more SPACEs at end of string with nothing
I wanted to come up with a small piece of code for removing preceding and trailing spaces. From what I have read in my JavaScript O'Reilly, I can understand why the second line would not do what I want. But I really don't understand why the first line keeps leaving ONE space if QstrVal has a value of, for example, " test". Won't the \s+ match all preceding white space?