First, don't use "\\[", use "[", otherwise you are scanning for backslash as well. Second, I don't see why this is necessary. Won't the result always be NULL, since you are scanning beyond the length of match? Could be that I missed something obvious, but I think the "sp = ..." further down is all that's necessary.