match the string algorithm