def extract_from_query(term, filter, regexp, end_of_word_boundary=True):
 re_string = ('\\b%s:\\s*(%s)' % (filter, regexp))
 if end_of_word_boundary:
  re_string += '\\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)

def extract_from_query ( term , filter , regexp , end_of_word_boundary = True ) : re_string = ( '\\b%s:\\s*(%s)' % ( filter , regexp ) ) if end_of_word_boundary : re_string += '\\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 )
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 .