[removed] what's the point of RegExp.compile()?

后端 未结 4 1522
刺人心
刺人心 2020-12-05 09:13

I\'ve got a situation where I want to get a regexp from the user and run it against a few thousand input strings. In the manual I found that the RegExp object h

4条回答
  •  醉梦人生
    2020-12-05 10:01

    You have to compile your regex first to use it if you are using /, try this out:

    var regex=new RegExp('/[a-zA-Z]/')
    
    console.log("not compiled with escape /", regex.test("ciao") )
    
    regex.compile()
    
    console.log("compiled", regex.test("ciao") )
    
    var regex=new RegExp('[a-zA-Z]')
    
    console.log("not compiled, but no escape /", regex.test("ciao") )

提交回复
热议问题