def is_valid_match(match, text):
    """True unless the match starts or ends in the middle of a word."""
    end, phrase_mapping = match
    start = end - phrase_mapping.phrase_length + 1
    return (end + 1 == len(text) or not text[end + 1].isalnum() or not text
        [end].isalnum()) and (start == 0 or not text[start].isalnum() or 
        not text[start - 1].isalnum())
