Ad
  • Custom User Avatar

    The ^ symbol means "at the start of the string"--meaning the original string. It doesn't know about the internal implementation of how your code is finding the index. So feel free to chop up the string if you wish, but bear in mind that the regex needs to properly match the original string.

    To demonstrate:

         "abcba".indexOf(/^c/, 2)
    //      ^-- check from here on
    //      ^ "c" found, but it doesn't start at the beginning of the string
    //      there are no more "c"s
                 == -1 // (no matches)