matching text algorithm