Test case details

Preparation Code

<script>   document.cookie="TEST_COOKIE=RegEx_vs_indexOf";function getCookieRegEx(c,a){var b=a.match(RegExp(c+"=([^;]*)"));return b&&b.length>0?b[1]:""}function getCookieIndexOf(c,a){var c=" "+c+"=",b,a=" "+a+";";return(b=a.indexOf(c))>=0?(b+=c.length,a=a.substring(b,a.indexOf(";",b))):""}; </script>

Test cases

Test #1

getCookieRegEx("TEST_COOKIE", document.cookie);

Test #2

getCookieIndexOf("TEST_COOKIE", document.cookie);