DEV Community

Discussion on: Regex Bootcamp (or Nobody Seems to be Using HTML5 Validation)

Collapse
 
anargh profile image
anargh

"you cannot assign a regex defined as a literal to a variable"

I'm not sure if I got this right and could probably a stupid question. But by saying you cannot assign, do you mean that the following is invalid or frowned upon?

const myRegex = /^\d{0,5}$/;
Collapse
 
dexygen profile image
George Jempty

Hmm I could be wrong I was trying something like this but it was barfing on the \d I think, as soon as I used new RegExp and escaped the \d with a slash it worked.