tools.py 359 B

12345678910111213141516
  1. import re
  2. def parse_like_term(term):
  3. """
  4. Parse search term into (operation, term) tuple
  5. :param term:
  6. Search term
  7. """
  8. if term.startswith('^'):
  9. return '^{}'.format(re.escape(term[1:]))
  10. elif term.startswith('='):
  11. return '^{}$'.format(re.escape(term[1:]))
  12. return re.escape(term)