Regular expressions

From Tabbles Wiki
Revision as of 11:50, 9 April 2018 by Andrea (talk | contribs) (Library of working regular expressions)
Jump to: navigation, search

Since the version 1.5.2 you can use regular expressions within the auto-tagging rules to tag files based on their name/path.

What are the regular expressions and how do they work?

- on wikipedia

- Page on Codeplex

- Online regular expression editor RegExr

- Download Expresso, a regular expression editor

- The reference page on MSDN

- Regular expression library (warning: the syntax could be different... the one on the MSDN page is the one that should work)

How do I use them in Tabbles?

Go to: Tools > Auto-tagging rules > New and edit the window to something like this:


From now on, whenever you create/save/rename a file/folder that matches tha regular expression, the file will be tagged (and a one-click pop-up should come up too).

If you want to automatically tag the files you already have, you need to use the function Tools > Run rules now. In order to use this function you need to first select a folder/disk within Tabbles.

Pocket size tutorial

Let's analyze a working regular expression:

.*\.avi$|.*\.mov$|.*\.mpg$ This one matches .avi OR .mov OR .mpg. A little explanation:

.* = matches any character

\. = matches the character "." (the dot)

avi = matches the pattern "avi" (and also mov and mpg)

^ = beginning of the pattern to be matched (put this in the beginning of the thing you want to match)

$ = end of the pattern to be matched (append this at the end of the thing you want to match)

| = plain and simple logical OR

So, if you want to add another extension, like .mp3, you append |.*\.mp3$ to the previous expression.

Other interesting stuff:

\b = matches backslash, ^ = beginning of the line to be matched, the opposite of $

Well, the rest is in the msdn reference...

Library of working regular expressions

This is a list of working regular expression: to contribute or request new ones, post in the forum thread :-)

Expression Effects Author
.*\.avi$|.*\.mov$|.*\.mpg$ matches .avi OR .mov OR .mpg Andrea
.*England.*|.*Great.*Britain|.*United.*Kingdom.*|.*Northern.*Ireland|.*Wales.*|.*Scotland.* matches "Great Britain", "Great_Britain", "Great-Britain" (along with the rest of the UK) etc. Andrea
.*(201\d).* matches 2010 to 2019 (useful for years). Change "201" to "200" to match 2000 to 2009 Andrea
.*C\d{3}.* Matches files with a path like "D:\Customers\C001" to "C999" or "...\stuff_C001_stuff" (to ...C999) Andrea
.*(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]).* Email address Andrea
[0-3][0-9][0-1][1-9]\d{2}-\d{4}?[^0-9]* Danish CPR Number (DDMMYY-NNNN, like 310180-1234) Andrea
.*(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}.*|.*(?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4}.*|.*(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}\s(?!00)\d{2}\s(?!0{4})\d{4}.* USA Social Security Number (It recognizes the formats 123456789, 123 45 6789, 123-45-6789) Andrea
.*(?:(?:[B-DF-HJ-NP-TV-Z]|[AEIOU])[AEIOU][AEIOUX]|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[1256LMRS][\dLMNP-V])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[1-9MNP-V][\dLMNP-V]|[0L][1-9MNP-V]))[A-Z].* Italian "Codice Fiscale" Andrea
.*\.(?:doc|pdf|chm|ppt|xls|rtf|docx|xlsx)$ matches .doc OR .pdf etc Renincuente
.*\b3x\d\d\b.* matches "season 3" (e.g. *3x01*,*3x01* etc) Maurizio
(?>.*\.)(?!(?:dll|cfg)$).*$ EXCLUDES .dll and .cfg files. Matches all the others Renincuente
(?:\w*_)?\d{2}-04-\d{4}(?:_\w*)? Matches pics taken in the month of April, named like Name_23-04-2010 or 23-04-2010_Name KaptK

Hint: be careful with the dots and the crazy characters - dont' lose half of them while copy-pasting!