using binary search instead of regex