My regEx doesn't work in my code

Hi there,

I’m building a regex to match the string of a website such as

I’m doing something very basic here and my regex is the following:


In it matches the string but in my code I do:

let URLvalidator = new RegExp('^(https?:\/\/)www.\$');


Both return false and I’m not getting why… I’m sure I’m missing something very obvious here. :sweat_smile:

Try adding the following right below the first line:


Does the pattern printed in the console look exactly like you want it to?

1 Like

Actually no… it prints /(https?://)
So it basically takes the backward slash out before the “w+”…

Okay I got it to work now, I needed to prepend the “\w+” with another "" so the working regEx looks like:

let URLvalidator = new RegExp('(https?:\/\/)www.\\');

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.