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

后端 未结 4 1527
刺人心
刺人心 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

    And with Opera 11, running RegExp.compile() will actually cause errors.

    Evidently, when Opera "compiles" a regex, it wraps the re.source string in forward slashes (e.g. re.source == "^(.)" becomes "/^(.)/"). If you manually compile the regex, Opera doesn't recognize this fact and goes ahead and compiles it again (re.source becomes "//^(.)//"). Each compile results in an extra set of forward slashes, which changes the meaning of the regular expression and results in errors.

提交回复
热议问题