Javascript Dynamic Regex Generation

前端 未结 1 861
后悔当初
后悔当初 2021-01-28 14:15

I want to make my alphanumeric regex dynamic in a way that it takes the allowed special characters with it as an argument by the user. Following is my code ... I am getting quot

相关标签:
1条回答
  • 2021-01-28 14:43

    You've actually escaped the quote, so you have to escape the escape

    var regex = new RegExp("^[a-z0-9_\\" + allowed + "]+$", "i");
    
    0 讨论(0)
提交回复
热议问题