Issue
I have this code .replace(/^(\d{0,3})(\d{0,2})/, '($1) $2');
.
I want to pass variable to make 3 dynamic.
I tried .replace(/^(\d{0,code.length})(\d{0,2})/, '($1) $2');
Thank you.
Solution
You can use RegExp
to fill your parameters up
const code = {
length: 3
}
const regex = new RegExp(`^(\d{0,${code.length}})(\d{0,2})`)
console.log(regex)
Answered By - Nick Vu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.