fix to end of string in C++ stack, checking end of match or word-boundary may fail under certain circumstances