Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  105] [ 4]  / answers: 1 / hits: 29465  / 15 Years ago, tue, may 19, 2009, 12:00:00

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 has a .compile() method which is used to speed things up ins such cases. But why do I have to pass the regexp string to it again if I already passed them in the constructor? Perhaps constructor does the compile() itself?


More From » regex

 Answers
48

The RegExp().compile() method is deprecated. It's basically the same as the constructor, which I assume is why it was deprecated. You should only have to use the constructor nowadays.



In other words, you used to be able to do this:



var regexp = new RegExp(pattern);
regexp.compile(new pattern);


But nowadays it is not any different from simply calling:



var regexp = new RegExp(pattern);
regexp = new RegExp(new pattern);

[#99501] Friday, May 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elmer

Total Points: 432
Total Questions: 96
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;