
How can I search using only wildcards (*) and - ?
Hi there,
I'd like some advice on how I could search the body of all my emails for the pattern "****-******-****" which is the pattern of an Amazon gift code. Could you suggest an Add-on or other way to search for that pattern?
Chosen solution
You might get false positives. I just ran this filter on my amazon folder and it came up with a hit.
No gift code, but it found this:
" 2016-Footer-S"
which matches the pattern above.
It might work with a trailing space in the pattern, but the success depends on where the code appears. I'd try this:
br:/ [a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9][ \n\t\r]/i
…so it looks for a space, tab or newline after the gift code and refuses a match like that I found above. RE's are a bit of a black art. ;-)
The painful next bit for you is finding that detected gift code inside the selected messages.
Oh, you might get a screenful of error messages, particularly if there are no matches. These are a nuisance but seem to be non-fatal.
Read this answer in context 👍 0All Replies (9)
Hello, I never did it but this module may help you.
Thanks for your reply! Unfortunately this Add-on does not help as it shows a "no results" message although there are several results to be found..
Modified
I'd use a RE ("regular expression") for that kind of search, but unfortunately I can't confidently suggest any tool that applies RE to the body text of email messages. Where I do have RE's, IIRC they are limited to being used in only addresses and subjects.
I don't have Thunderbird here with me now, but I think it may be possible to use RE's on message text using the Expression Search addon you already have. I will check this later on today when I have Thunderbird to hand.
Expression Search does indeed support RE's in body text.
For instance, this:
br:/ [0-9]{3}\-[0-9]{3}\-[0-9]{4}/
will find messages in the current folder containing US-style phone numbers (3 digits, dash, 3 digits, dash, 4 digits)
If you can come back with the precise specification for your gift codes, we can work out an RE to detect them.
Note that Expression Search modifies the QuickFilter and so only operates on the current folder. If you need to search over multiple folders, use ctrl+shift+f to start a generic search, insert this search pattern as a filter rule, such as:
Body (RegEx)|matches|br:/ [0-9]{3}\-[0-9]{3}\-[0-9]{4}/
…then convert it into a Saved Search, where you can specify which folders to include. Note that Expression Search adds its own filter capabilities to the generic filter and search tools.
Thanks for your help! The precise definition of these amazon codes would be 4times a random letter or number followed by an - and 6 times a random letter or number followed by - and a random letter or number. So would code would that translate in to?
shnil said
Thanks for your help! The precise definition of these amazon codes would be 4times a random letter or number followed by an - and 6 times a random letter or number followed by - and a random letter or number. So would code would that translate in to?
br:/ [a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9]/i
br: : tells Expression Search you're doing an RE on the message body / : start of an RE pattern : I deliberately inserted a space at the start of the pattern so we don't pick up any numbers embedded inside another word [a-z0-9]{4} : any letter or numeral times 4 \- : a dash; the backslash is used to force it to be treated as a literal hyphen and not have any magic properties. Probably not essential, but it works when done like this. [a-z0-9]{6} : any letter or numeral times 6 \- : another dash [a-z0-9] : any letter or numeral times 1; I have assumed it is a single character here, but you can see how to use {*} to determine a number of repeats. / : end of the pattern i is a switch that says "ignore case", so a-z also matches A-Z
Instead of the i switch at the end we could have used [a-zA-Z0-9] within the RE. There are also keywords that more elegantly might say "any alphanumeric" but they are a bit implementation dependent. Employing the basic commands I've used here is more sure to work.
Modified
Chosen Solution
You might get false positives. I just ran this filter on my amazon folder and it came up with a hit.
No gift code, but it found this:
" 2016-Footer-S"
which matches the pattern above.
It might work with a trailing space in the pattern, but the success depends on where the code appears. I'd try this:
br:/ [a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9][ \n\t\r]/i
…so it looks for a space, tab or newline after the gift code and refuses a match like that I found above. RE's are a bit of a black art. ;-)
The painful next bit for you is finding that detected gift code inside the selected messages.
Oh, you might get a screenful of error messages, particularly if there are no matches. These are a nuisance but seem to be non-fatal.
Thanks a lot! Your help and knowledge is much appreciated! I've just been trying to solve the same problem you've just suggested to solve by using: br:/ [a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9][ \n\t\r]/i For some reason using this shows up with zero results although there definitely are spaces, newlines or tab after and before the giftcodes. Tried putting it in the front too with br:/ [ \n\t\r][a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9]/i without any success. Is there a way to export the matches for the br:/ [a-z0-9]{4}\-[a-z0-9]{6}\-[a-z0-9]/i search directly to a document/clipboard? If so I might as well just filter the false ones out myself...
I managed to solve it by using the regex code you provided together with Expresso by Ultrapico Editor. Thank you! :-)