February 11th, 2009, 09: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 11th, 2009, 11:27 PM
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, 02: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, 03:53 AM
Originally Posted by threequestions
Don't worry about it unless you start noticing (or people start complaining about) lag.