From bb04405cd633d77c8395026e7be3f1698032cb03 Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 17 Dec 2013 10:06:13 -0600 Subject: [PATCH] add unicode and ignore case regex flags --- bin/autojump | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/autojump b/bin/autojump index 7d0b7c7..3e6929c 100755 --- a/bin/autojump +++ b/bin/autojump @@ -30,7 +30,7 @@ from operator import attrgetter from operator import itemgetter import os import platform -from re import search +import re import sys from argparse import ArgumentParser @@ -208,7 +208,7 @@ def find_matches(config, needles, count=1): return first(exact_matches).path -def match_exact_regex(needles, haystack): +def match_exact_regex(needles, haystack, ignore_case=False): """ Performs an exact match by combining all arguments into a single regex expression and finding matches. @@ -222,9 +222,9 @@ def match_exact_regex(needles, haystack): result = [(path="The quick brown fox jumped over the lazy dog", 12.3)] """ - regex_needle = '.*' + '.*'.join(needles) + '.*' - find = lambda haystack: search(regex_needle, haystack.path) + regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE + find = lambda haystack: re.search(regex_needle, haystack.path, flags=regex_flags) return ifilter(find, haystack)