Converting user input string to regular expression

前端 未结 11 2003
无人及你
无人及你 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:40

    Use the JavaScript RegExp object constructor.

    var re = new RegExp("\\w+");
    re.test("hello");
    

    You can pass flags as a second string argument to the constructor. See the documentation for details.

提交回复
热议问题