commit bc54fa197aca91cd92577b7223b4db8cbf3bba7b
parent 4a0eaa212db7f0b6ebc226e5695dfc89d706da14
Author: Samuel Walladge <samuel@swalladge.id.au>
Date: Mon, 23 Jan 2017 14:11:40 +1030
allow case-insensitive regex searching
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/simplenote_cli/notes_db.py b/simplenote_cli/notes_db.py
@@ -11,6 +11,7 @@
from . import simplenote
simplenote.NOTE_FETCH_LENGTH=100
from .simplenote import Simplenote
+import logging
class ReadError(RuntimeError):
pass
@@ -239,9 +240,20 @@ def filter_notes_regex(self, search_string=None):
Each element in the list is a tuple (local_key, note).
"""
sspat = None
+ valid_flags = {
+ 'i': re.IGNORECASE
+ }
if search_string:
try:
- sspat = re.compile(search_string)
+ search_string, flag_letters = re.match(r'^(.+?)(?:/([a-z]+))?$', search_string).groups()
+ flags = 0
+ # if flags are given, OR together all the valid flags
+ # see https://docs.python.org/3/library/re.html#re.compile
+ if flag_letters:
+ for letter in flag_letters:
+ if letter in valid_flags:
+ flags = flags | valid_flags[letter]
+ sspat = re.compile(search_string, flags)
except re.error:
sspat = None