Regular Expression Know-How needed

Hello Experts,

I'm suffering from a severe lack of Regular Expression know-how. Here's my problem: I am searching through a folder looking for specific files. Files with the extension .cck. Now the tricky part I want to exclude any file starting with 31DF1 or 31DF1\w\w\w\.cck to be precise. The filter that I came-up with on my own is
this one: "\w\w[^D]\w\w\w\w\w\.cck" and it works quite well, however I want to make it safer and more powerful. As you can see, I'm using [^D] or not D, because I'm pretty sure no other file will have a D as the third character. At first I thought using "\w\w[^D][^F]\w\w\w\w\.cck" would get me closer to my goal but after further testing it was of no value. What I really want to do is just exclude the file 31DF1\w\w\w\.\w\w\w with the same power that I have to find
31DF1\w\w\w\.\w\w\w.
Regular Expressions allow the 31DF1 in  
31DF1\w\w\w\.\w\w\w to be an AND when grouped but do not produce the same AND value between the special characters when using [^3][^1][^D][^F][^1] giving
me the same power to exclude as I have to find. Here is my code:

Filter = "\w\w[^D]\w\w\w\w\w\.cck"
ANS as Boolean
For Each file In FileCollection
ANS = TestRE(Filter, File, True)
If ANS = True Then
MsgBox ANS
End If
Next

Public Function TestRE(Filter As String, Source As String, Optional NoCase As Boolean = False) As Boolean

    Dim myRE As RegExp
    Set myRE = New RegExp
    TestRE = False
    myRE.Pattern = Filter
    myRE.IgnoreCase = NoCase
    TestRE = myRE.Test(Source)

End Function
dominica526Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shiju SasidharanAssoc Project ManagerCommented:
Hi

u r actually dealing with file name , so it is better to set         NoCase = True     always
try this pattern

    Filter = "(31DF1)*\w*\.cck"

;-)
Shiju
0
Shiju SasidharanAssoc Project ManagerCommented:
hi
me again
this pattern will match the occurence of ur specified patern
;-)
Shiju
0
dominica526Author Commented:
Thank you shijusn.

This is very nice, but I want to exclude that file. However in your pattern what does the () do for the 31DF1 and what does the * before the \w do?

Filter = "(31DF1)*\w*\.cck"

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Shiju SasidharanAssoc Project ManagerCommented:
hi

well u want to exculde those files with name 31df1.cck or filenames start with 31df1 isnt it ?
ok wait...

;-)
Shiju
0
Shiju SasidharanAssoc Project ManagerCommented:
hi  dominica526
 try this

'----------------------------------------------------------
Private Function FindMatchFileName(ByVal sSource As String) As Boolean
Dim objRegExp As New RegExp
Dim objMatchCol As MatchCollection
    With objRegExp
        .IgnoreCase = True
        .Global = True
        .Pattern = "31DF1\w*\.cck"
    End With
    FindMatchFileName = False
    Set objMatchCol = objRegExp.Execute(sSource)
    If objMatchCol.Count > 1 Then FindMatchFileName = True
    Set objRegExp = Nothing
End Function

Private Sub Command1_Click()
    If FindMatchFileName("Your_File_name_to_check") Then
        MsgBox "Specified File Name Found"
    Else
        MsgBox "Specified File Name NOT Found"
    End If
End Sub

'------------------------------------------------------------------

;-)
Shiju
0
Shiju SasidharanAssoc Project ManagerCommented:
hi
me again , sorry one modification

>>If objMatchCol.Count > 1 Then FindMatchFileName = True

change above statement to

          If objMatchCol.Count > 0 Then FindMatchFileName = True

;-)
Shiju

0
Shiju SasidharanAssoc Project ManagerCommented:
hi dominica526

>>Filter = "(31DF1)*\w*\.cck"
>>what does the * before the \w do?

   u were right there was no need for that * before \w in my first comment
only "\w+\.cck"  was enough to match any filename with cck extension
if ur file name inculdes SPACE aswell then change it to "[\w ]+\.cck"
if u want to find file name starting with "xyz" use         "xyz\w+\.cck"
if u want to find file xyz.cck or name starting with "xyz" use      "xyz\w*\.cck"

;-)
Shiju








0
dominica526Author Commented:
Shijusn.

You are basically saying with this code that if you find the file then return false instead of true. This doesn’t help my situation because I am using the FOR EACH loop to select many files with wide ranging criteria. While doing this I don’t want to pick-up a very specific file, 31DF156.cck. This pattern does the trick for me: "\w\w[^D]\w\w\w\w\w\.cck but only because so far there have been no other files with a D in the third position. I need to make a pattern that would exclude the 31DF156.cck file with including all other files.
0
Shiju SasidharanAssoc Project ManagerCommented:
Hi
u r saying that u want to exclude all those files with third letter as "D" or "d" ?
if my assumption is correct
u want to exclude files like
      31DF156.cck
      abd4566.cck
      34Dastdf334d.cck
      ......
      .......
in other words u want the result to be true if specified file is none of the above

;-)
Shiju
0
dominica526Author Commented:
Shiju

Your assumption is correct about my current pattern. There is just one file that I am trying to exclude 31DF1\w\w\w\.cck  with the current date being covered by \w\w\w. Any file in this folder that starts with 31DF1 needs to be excluded. My pattern "\w\w[^D]\w\w\w\w\w\.cck" works fine or at least until another file shows-up with a “D” or a “d” in the third position.  My current pattern excluded just the d, I want to make my pattern more powerful so but now I’m trying this pattern "[^3][^1][^D][^F]\w\w\w\w\.cck" and so far I can’t seem to get it to fail. The documentation I have states that [^] is used for a NOT but it only shows alpha but I think it woks with numbers as well. The problem is that the logic being applied by using [^3][^1][^D][^F] is not as a group, so I’m trying  this pattern "([^3][^1][^D][^F])\w\w\w\w\.cck" but I don’t know if it’s working.
0
Shiju SasidharanAssoc Project ManagerCommented:
hi
i dont understand y do u stick on to remove/exclude the pattern match instead of finding that match and skiping the situation. i would like to say that it is better to find a match for a pattern
u know rather than finding an opposite match for the pattern

to achieve ur result(get excluded result) i think
   "\w{2}[^Dd]\w+\.cck"
       
      will be enough

;-)
Shiju
 
0
Shiju SasidharanAssoc Project ManagerCommented:
hi
i think there is no way to find "Not operator" Result for a word or string in regular expression.
Only character by character negation is there as u tried([^3][^1][^D][^F])
;-)
Shiju
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dominica526Author Commented:
It is easier to exclude just one file because the rest of the files will all be included. As part of the FOR EACH loop I pick-up all the files in this folder while leaving that single file. Your patter \w{2}[^Dd]\w+\.cck is the same as mine, you allow 22D489.cck to be picked up.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.