0

I am trying to check if there is whitespace just before forward slash / in string JS. I have this code now const reWhiteSpace = new RegExp("\s(?=[^/\s]*/)"); reWhiteSpace.test(values.body). But it is not working as expected.

qweeee
  • 63
  • 1
  • 2
  • 8
  • That should probably be `/\s[/]/.test(values.body)`. – Sebastian Simon Sep 13 '21 at 06:10
  • you can try a manual approach, looping till you find a `/`, then checking its previous index – ahsan Sep 13 '21 at 06:11
  • @SebastianSimon, I tried but always get false, here is my code : const reWhiteSpace = new RegExp("/\s[/]/"); reWhiteSpace.test(values.body) – qweeee Sep 13 '21 at 06:16
  • Why wrap it in a `RegExp` constructor? Single backslashes are not going to work there: [Why do regex constructors need to be double escaped?](/q/17863066/4642212). – Sebastian Simon Sep 13 '21 at 06:16

0 Answers0