As of now, I am trying to achieve successfully with static values for eg.,
maskRe: /^[A-Za-z0-9 $%] $/
but I wanted to pass $% dynamically with some variable instead of hardcoding.
CodePudding user response:
You can use RegExp
class to create a RegExp
object from a string. The string can be as static as a formatted.
let dynamicValue = "$%";
let regex = new RegExp(`^[A-Za-z0-9 ${dynamicValue}] $`);
console.log(regex);