let hello = " Hello, World! "; let wsRegex = /^\s*(.*\S)\s*$/; let result = hello.replace(wsRegex, "$1");