S3Sync.net

General Category => Questions => Topic started by: Glyn on October 27, 2007, 03:49:53 AM



Title: --exclude and regular expressions.
Post by: Glyn on October 27, 2007, 03:49:53 AM
Hi,

I am trying to get my head around how regular expressions work, perhaps I'm being a bit stupid, but I haven't got my head around them properly yet.  Can someone give me a hand in setting this up?  I think I have a common situation, where I want to exclude the following:

all contents in directories that end in __XB
all directories and their contents called @eaDir (ok, just the contents is fine)
all files with the extension .CR2
all files called thumbs.db

so, with the help of the previous topic regarding multiple excludes, I end up with:

--delete --exclude "(?:__XB/|@eaDir/|*.CR2|thumbs.db)"

but I get an error message (due to the *),so I then read up a bit more on regex's and tried this:

"(?:__XB/|@eaDir/|thumbs.db|<[A-Za-z0-9]+><.>CR2)"

however, this still backups my CR2 files, can someone advise me where I'm going wrong?

Thanks in advance,
Glyn.

PS, I have the --delete so that if I rename a directory with __XB then it will be excluded from the backup and removed from s3


Title: Re: --exclude and regular expressions.
Post by: maelcum on October 27, 2007, 03:21:49 PM
Hi Glyn,  :D

leave out the "*".
Try: --exclude "(?:__XB|@eaDir|.CR2|thumbs.db)"

Cheers.

maelcum


Title: Re: --exclude and regular expressions.
Post by: Glyn on October 29, 2007, 09:49:48 AM
Yep, hi, I guess this was a natural progression from the synology forum!

I think that I tried that without success (can't test now, as at work at present).  Is this something that you have working?

Cheers,
Glyn.


Title: Re: --exclude and regular expressions.
Post by: maelcum on October 29, 2007, 04:58:20 PM
Yes, it works for me. That way I'm not saving files that have a .log-ending.


Title: Re: --exclude and regular expressions.
Post by: ferrix on October 30, 2007, 02:06:46 AM
Hi guys.  I like regularexpressions.info for a good reference.  There is also software that can test a regex against a particular string to see what it will do.

For example online: http://makedatamakesense.com/regex_debug/

Next I will try to look at your regex to see what it does.


Title: Re: --exclude and regular expressions.
Post by: ferrix on October 30, 2007, 02:18:21 AM
"(?:__XB/|@eaDir/|thumbs.db|<[A-Za-z0-9]+><.>CR2)"

I'm not sure what you are trying to do above with all the angle brackets... Maybe you were looking at some strange dialed of regex.  ;)

In regex dot "." means any character.  * means "zero or more of"

I think what you might have wanted to say at first was ".*CR2"
which says "zero or more of any character followed by CR2"

maelcum's example will exclude anything that contains the characters CR2 preceded by one wildcard character.  What he should probably do for his log files is like "[.]log"

Because when you put period inside character class brackets it means really dot.  You can also escape stuff with backslashes
so like
\.log

If your command shell is complaining or doing bad things with all these special characters like * $ etc. try using single quotes for wrapping the regex string instead of doubles.  In many interpreters, single quotes mean "leave this string alone"


Title: Re: --exclude and regular expressions.
Post by: Glyn on October 30, 2007, 03:04:35 AM
Thank you both for your articulate  ;D replies.

.CR2 now appears to work, although I could have sworn that it didn't the other day (another case of self healing software!  :) )

Thanks for the links Ferrix, I will be making my exclude command more comprehensive so this will be very helpful in setting up more complex regex's

Glyn.

PS, the angled brackets came from some web site that I was using as a guide to regex's - I'd never encountered them before.


Title: Re: --exclude and regular expressions.
Post by: maelcum on October 30, 2007, 04:46:16 AM
online: http://makedatamakesense.com/regex_debug/

Wow! Thanks Ferrix. Thats a good site!   8)