import re


def approx_field_predicate(field, value, args):
    """Return a function that does an approximate match of a string."""
    flags = re.I if args.ignore_case else 0

    def _approx_match(entry):
        field_value = getattr(entry, field, None)

        if field_value is None:
            return False
        else:
            return re.search(value, field_value, flags)

    return _approx_match