Converting user input string to regular expression

前端 未结 11 1949
无人及你
无人及你 2020-11-22 14:18

I am designing a regular expression tester in HTML and JavaScript. The user will enter a regex, a string, and choose the function they want to test with (e.g. search, match,

11条回答
  •  春和景丽
    2020-11-22 14:46

    Use the RegExp object constructor to create a regular expression from a string:

    var re = new RegExp("a|b", "i");
    // same as
    var re = /a|b/i;
    

提交回复
热议问题