Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I need to check the following with 4 being the variable.
4
'1212'.match(/\d{4}/)
I know I can use '1212'.match(new RegExp(jamie)) to pass a variable into a regex, but then I don't know how to check for digits \d side of things.
'1212'.match(new RegExp(jamie))
\d
RegExp()
You can build a string with proper escaping and than using RegExp constructor you can build regex
let temp = 4 let reg = `\\d\{${temp}\}` let regex = new RegExp(reg) console.log('1212'.match(regex))
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
RegExp()expects a string (or a regex pattern). So...