Tell us what’s happening:
Why is this regex not able to select a string with whitespaces at beginning and the end and then replace it with the middle string only(without the extreme spaces)?
Your code so far
let hello = " Hello, World! ";//string with spaces at start and end let wsRegex = /^\s*(.+)\s*$/; // regex to select a string (.+) with spaces at beginning and end let result = hello.replace(wsRegex, "$1"); // replacing the selected text with the string enclosed between the spaces console.log(result); //it does log "Hello, World!" as expected but test-run gives the error <error>result should equal to "Hello, World!"</error>
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75.
Challenge: Remove Whitespace from Start and End
Link to the challenge: