February 11th, 2009, 10:29 PM
I have three ways to check for a pattern within a string.
string.match(pattern) // just checks for match
pattern.exec(string) // can return array with backreferences, etc, then check for match within reference
pattern.test(string) // just checks for match
Which is faster, if even applicable? I know this can also depend on the browser, but inherently, which is faster?
February 12th, 2009, 12:27 AM
It probably depends on the implementation. Not just speed but what's better.
For example, regexp.exec could simply call off string.match or regexp.text and return whether there was a match to begin with. In which case it's slower than the other two.
Or the implementation could be nice and actually do the work, where it'd probably be faster than the others.
Just do whatever makes most sense to you.
February 13th, 2009, 03:16 AM
Thanks for the input requinix. I decided on exec because I needed to have some values returned from the backreferences.
February 13th, 2009, 04:53 AM
Originally Posted by threequestions
Don't worry about it unless you start noticing (or people start complaining about) lag.