Why not use matchAsPrefix and only check match.end == str.length?