mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #169 from luoliyan/regex-tag-removal
Allow wildcard tag deletion
This commit is contained in:
commit
9f37cddfda
1 changed files with 6 additions and 3 deletions
|
@ -103,7 +103,7 @@ class TagManager:
|
|||
res = self.col.db.all(
|
||||
"select id, tags from notes where id in %s and (%s)" % (
|
||||
ids2str(ids), lim),
|
||||
**dict([("_%d" % x, '%% %s %%' % y)
|
||||
**dict([("_%d" % x, '%% %s %%' % y.replace('*', '%'))
|
||||
for x, y in enumerate(newTags)]))
|
||||
# update tags
|
||||
nids = []
|
||||
|
@ -140,13 +140,16 @@ class TagManager:
|
|||
return self.join(self.canonify(currentTags))
|
||||
|
||||
def remFromStr(self, deltags, tags):
|
||||
"Delete tags if they don't exists."
|
||||
"Delete tags if they exist."
|
||||
def wildcard(pat, str):
|
||||
pat = re.escape(pat).replace('\\*', '.*')
|
||||
return re.search(pat, str, re.IGNORECASE)
|
||||
currentTags = self.split(tags)
|
||||
for tag in self.split(deltags):
|
||||
# find tags, ignoring case
|
||||
remove = []
|
||||
for tx in currentTags:
|
||||
if tag.lower() == tx.lower():
|
||||
if (tag.lower() == tx.lower()) or wildcard(tag, tx):
|
||||
remove.append(tx)
|
||||
# remove them
|
||||
for r in remove:
|
||||
|
|
Loading…
Reference in a new issue