I’m building a regex to match the string of a website such as https://google.com
I’m doing something very basic here and my regex is the following:
In https://regexr.com it matches the https://google.com string but in my code I do:
let URLvalidator = new RegExp('^(https?:\/\/)www.\w+.com$');
Both return false and I’m not getting why… I’m sure I’m missing something very obvious here.
Try adding the following right below the first line:
Does the pattern printed in the console look exactly like you want it to?
Actually no… it prints /(https?://)www.w+.com/
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.\\w+.com');