import re


def extract_from_query(term, filter, regexp, end_of_word_boundary=True):
    """
    This pulls out a keyword filter from a search term and returns the value
    for the filter and a new term with the filter removed.

    E.g. term="yslow version:3", filter='version', regexp='\w+' will result in
    a return value of: (yslow, 3).
    """
    re_string = r'\b%s:\s*(%s)' % (filter, regexp)

    if end_of_word_boundary:
        re_string += r'\b'

    match = re.search(re_string, term)
    if match:
        term = term.replace(match.group(0), '').strip()
        value = match.group(1)
    else:
        value = None

    return (term, value)