Announcement

Collapse
No announcement yet.

Filename Filter Failed: a RegEx (Regular Expressions) problem?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filename Filter Failed: a RegEx (Regular Expressions) problem?

    I am unable to filter filenames that contain the character "[". After experimentation, reading BComp Help and the Scooter Forums, I think my problem is due to the >FolderCompare >NameFilters interpreting my filename strings as Regular Expressions.

    As an example, I have many files with "[" and "]" embedded within their name, for example, my[OLD]Data.txt When I include the string, *[OLD]* in the >FolderCompare >FileFilters >NameFilters >IncludeFiles:box, the results are nonsensical.

    As a temporary work-around, I used the string, *OLD]* which seemed to work. So I guessed that the leading "[" triggered RegEx behavior. I did some research and tried using the RegEx escape character, "\" as follows, *\[OLD\]* and *\[OLD]* but neither worked.

    After more research, I tried *[[]OLD]* which worked, so I concluded that RegEx was operative. I don't use RegEx and don't want to learn their intricacies. It would be useful to either (1) have an option to turn ON/OFF RegEx in NameFilters, or (2) implement a way to escape reserved RegEx meta characters. By the way, what other chars could cause related problems?

    If I am off-track, please set me straight. I don't use RegEx and don't want to learn their intricaies, but I just want to filter as simply as resonable.

    I am using BComp 3.1.11 WinXP, SP3. Thanks for any help.

  • #2
    Hello,

    The trick is to escape the [ character by surrounding it with []. So [[]OLD] is the expected method to handle this. Our file name filters use a small subset of masking characters, and is not a full RegEx engine. The options available are covering the in the Help file in the Settings Reference: Session Settings: Folder Compare: Name Filters section and the File Masks link. In quick summary, the options available are: ?, *, [!], and .\

    If you have any questions about any of these commands, please let us know.
    Aaron P Scooter Software

    Comment


    • #3
      Suggestion to clarify the use of RegEx

      Thank you for the prompt reply, which I understand. What a coincidence that I stumbled into the solution after studying RegEx for a day. However, I would like to note the following.

      1. Many users are not well-versed in RegEx, and in fact may have never used it (like me).

      2. After my day of RegEx self-study, a basic concept I came away with is the universal escape character, backslash “\”, which does not work in NameFilters. I can see that if BComp were to use the backslash "\", it would immeasurably complicate NameFilters because Windows (DOS) uses backslash as the path delimiter.

      3. Unfortunately, when BComp included the RegEx concept of classes using brackets, "[...]" for NameFilters (ref. Settings Reference: Session Settings: Folder Compare: Name Filters section and the File Masks link), it embedded a landmine waiting to confound unsuspecting Windows users who are familiar with only two wildcards: * and ? (and sometimes not even the latter).

      4. As I noted in my initial post, only the opening bracket "[" triggers the landmine. The closed bracket "]" is innocuous and works like any other literal. So it seems the landmine is only a single character, "[" The incorrect results arising from using “[“ as a literal might confound unknowing users (as I was), who may not even notice the effects. (Among 258 files, I did not notice the "[OLD]" were not excluded because I’ve used BComp for several years and I thought I understood the FileFilters quite well: ? and * are wildcards and everything else is literal, with the all addition of nifty relative paths). So “[“ is more like a Trojan than a landmine, as it poses innocently, but causes unexpected results whenever used as a literal.

      5. As an aide to minimize victims of this somewhat complex and stealthy "feature," I have two alternate suggestions.

      5.1. In the "Folder Compare - Session Settings - Name Filters" window, next to the "Clear" button, place an empty checkbox labeled something like, "Use special RegEx match", which would be a blue underlined link to "Settings Reference: Session Settings: Folder Compare: Name Filters section and the File Masks link", and would activate the RegEx class "[...]". Most users would NOT select this checkbox option, so “[“ would remain literal and ? * are wildcards; this would be as with most other Windows apps. The checkbox option itself would hopefully alert users to the stealthy (and sometimes useful) “[“ RegEx class feature.

      5.2. In the "Folder Compare - Session Settings - Name Filters" window, next to the "Clear" button, place two radio buttons (mutually exclusive) labeled something like, (a)"Use * and ? wildcards" and (b)"Use special RegEx match", which would be a blue underlined link to "Settings Reference: Session Settings: Folder Compare: Name Filters section and the File Masks link."

      6. I prefer option 5.2 because it clearly establishes the alternatives and alerts users of a lesser used alternative.

      Sorry for the long post, but I have found BComp so very useful for several years that I did not even notice the incorrect results "[" were causing. Hope this may help at least one other BComp user.

      Comment


      • #4
        Hello,

        Thanks for the suggestions. We do use Regular Expressions heavily in our program, such as defining Grammar elements or the Find dialog. Our File Name Filters are not actually based on Regular Expressions, but are more closely linked to DOS Masking. Specifically, it uses a Unix filename wildcards, glob: http://en.wikipedia.org/wiki/Glob_(programming)

        As a side note: Adding additional support for Regular Expressions to the Filters is on our wishlist.

        I hope there was not too much confusion in dealing with these different systems. You can definitely apply this RegEx knowledge to the other areas of our application that support it (which will have a "Regular Expression" checkbox option below the text box to enable it.)

        If you ever have any questions about what is supported, please let us know via forum, email or phone call. You can also click the context sensitive help '?' button next to the 'X' close button; this will always take you to the Help article directly related to the dialog you are looking at.
        Aaron P Scooter Software

        Comment


        • #5
          Hi,

          Folder Compare >> Session Settings >> Misc >> Alignment overrides

          Is it possible to align such a list by using Regular Expression?

          SomeFolder.rar <--> Some Folder
          myfolderx.zip <--> My Folder X
          Anothersample.zip <--> Another Sample
          ...

          I tried this but didn't work:
          (.+?)(.+?)?(.+?)?(.+?)?\.(zip|rar)=\1 ?\2? ?\3? ?\4?

          Comment


          • #6
            Originally posted by B2C View Post
            Hi,

            Folder Compare >> Session Settings >> Misc >> Alignment overrides

            Is it possible to align such a list by using Regular Expression?

            SomeFolder.rar <--> Some Folder
            myfolderx.zip <--> My Folder X
            Anothersample.zip <--> Another Sample
            ...

            I tried this but didn't work:
            (.+?)(.+?)?(.+?)?(.+?)?\.(zip|rar)=\1 ?\2? ?\3? ?\4?
            Hello,

            How does this work for you?:
            Left = (.*)\.(zip|rar)
            Right = $1
            Aaron P Scooter Software

            Comment


            • #7
              But there are spaces in the names of the right side. I'd rather not remove them.

              Comment


              • #8
                BTW, a suggestion:
                Enhance [Align] command to do [Toggle Align], or add a [Dismiss] command. So that we can dismiss an aligned pair (or even pairs) conveniently.

                Comment


                • #9
                  Your replacement must result in an exact match of the text on the other side. Having extra spaces and changing character case complicates things significantly. There isn't any one regular expression that could successfully align all of your examples.
                  BC v4.0.7 build 19761
                  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                  Comment


                  • #10
                    Thanks for the hint. I changed things this way:
                    Swapped the sides.
                    Added such Alignment overrides:
                    (?i).+=$0.zip
                    (?i)(.+?) (.+)=$1$2.zip
                    (?i)(.+?) (.+?) (.+)=$1$2$3.zip
                    (?i)(.+?) (.+?) (.+?) (.+)=$1$2$3$4.zip
                    (?i).+=$0.rar
                    (?i)(.+?) (.+)=$1$2.rar
                    (?i)(.+?) (.+?) (.+)=$1$2$3.rar
                    (?i)(.+?) (.+?) (.+?) (.+)=$1$2$3$4.rar

                    Please let me know if it still can be optimized.

                    Comment


                    • #11
                      Align/AlignWith also has this problem:
                      http://www.scootersoftware.com/vbull...94&postcount=1

                      I hope the current position will be kept and the newly aligned pair will be focused.

                      Comment


                      • #12
                        The current expanded/collapsed state of every folder should also be maintained.

                        Comment


                        • #13
                          I agree that a newly aligned pair of files should remain visible on the screen keeping the current focus. I also confirm that this does not occur when aligning two files after scrolling down to a lower part of the directory.
                          BC v4.0.7 build 19761
                          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                          Comment


                          • #14
                            For example, Alignment override:
                            X=X.zip

                            X.zip on the right side exists.
                            Create the folder X (or rename a folder to X) on the left.
                            This pair would be aligned immediately. But there will be a message in the Log:
                            Unable to compare ...\X: Path is not a valid file.
                            Unless the list is fully refreshed.
                            Can't this message be avoided?

                            Comment


                            • #15
                              Hello B2C,

                              I'm testing out your zip example but it seems to align fine using the Alignment Override:
                              * = *.zip
                              and then creating the Folder on the Left does not cause the panes to scroll, it makes the folder and aligns it to the paired zip file.

                              Are you using the latest release of BC3 (currently 3.2.4)?
                              Could you post a screenshot showing your folder comparison displaying the error message? Which Alignment Override did you define?
                              Aaron P Scooter Software

                              Comment

                              Working...
                              X