Tell us what’s happening:
So I don’t know if I correctly understand what I’m to do. I tried capturing each word and using just that for the replace, and now I tired this and my thoughts are that I’m just capturing the string “Hello, World!” without the spaces and when I replace it with that group it doesn’t use the spaces. Should I be trying to capture only the white space? I tried to have wsRegex =^(\s)$ . sp the replace could just be ‘’ getting rid of the white space at the beginning and end. Sorry for the long post I’m just trying to get more information since I didn’t really find the hints to helpful and I don’t want to be spoiled on the answer. Advice is appreciated.
Your code so far
let hello = " Hello, World! ";
let wsRegex = /^\s(\w+\W\s\w+\W)\s$/; // Change this line
let result = hello.replace(wsRegex, '$1'); // Change this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0
Challenge: Regular Expressions - Remove Whitespace from Start and End
One of the easiest ways to solve this with a regular expression is to match one ore more whitespace characters at the beginning of the string OR at the end of the string. To match all such occurrences, you will need to use the global flag, otherwise replace will only replace the first ocurrence.
Thank you for your reply. I ended up giving up and looking at the given solution. The funny thing is I tried to do something very similar I just didn’t use OR as well as the + sign. I kept forgetting that I needed to account for the space occurring more than once. Anyway thank you for the reply, it’s frustrating though, I really felt good through most or this unit too but it’s problems like these that make me think I really didn’t understand anything I learned.sorry for the rant and thank you again for the reply.