regex vs indexOf (v2)

Revision 2 of this benchmark created by Pat Cavit on

Preparation HTML

  var ipadUserAgent = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10';
  var regex = /ipad/i;

Test runner

Ready to run.

Testing in
Sniffing Via Regex
ipad = regex.test(ipadUserAgent);
Sniffing Via indexOf
ipad = ipadUserAgent.indexOf('iPad') > -1;


You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Weiss I Nicht on
  • Revision 2: published by Pat Cavit on
  • Revision 3: published by Jonas Fischer on
  • Revision 4: published on
  • Revision 5: published on
  • Revision 6: published by vamp on
  • Revision 7: published by Leo Dutra on
  • Revision 8: published by Marco Pfeiffer on