Fix getLongestMatch. Consider only non-negative values, only at token end.