#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Regex for Clientbackup


    Hello,

    as a part of a Java Client Backup Project I need a Regex command.
    I want to exclude folders from the backup by Regex.

    Excludes like that are working fine:
    (?i).:/Program Files \(x86\)/.*
    (?i).:/Program Files/.*

    Now I search a Regex that excludes all folders of a drive except c:/Users/*

    I tried (?i).:/!(Users)/.* but this ist not workink.
    I also read a tutorial but didn't get informations about "all, but one not".

    One more examble:
    c:/Program Files/ >> match
    c:/Program Files/folder1 >>match
    c:/Windows/ >>match
    c:/Users/ >> no match
    c:/Users/User1 >> no match


    Would be perfect if someone can help me.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,921
    Rep Power
    1045
    Hi,

    is there a reason why you need this strange "exclude anything but x" logic instead of simply telling the program to include x and nothing else?

    Either way, an exclamation mark is no magical negation character. It's taken literally. The only way to exclude a certain expression would be through a negative lookahead:

    Code:
    c:/(?!Users)
    But double negatives are just weird. Better use positive matches (or fix your application if it can't do that).
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0
    Hi Jacques1,

    than you for your help.

    The Backup solution just allows excludes with RegEx. Normaly you exclude c:/windows or c:/Temp.
    Our Client strategy is that the users uses just c:/Users/xx folder. So we have to exclude all other folders. On the other site we don't want to force the user to backup the full user path. Users can choose all folders under c:/Users/____.

    My final Regex are working fine:
    Code:
    (?i).:/(?!Users).*/.*
    (?i).:/[^/]*\..*
    (?i).:/Users/AppData/.*              
    (?i).:/Users/Public/.*

IMN logo majestic logo threadwatch logo seochat tools logo