I have a smaller SSIS packat that I am trying to match a file name with VB Regex and delete “said” file. My regex looks like this, ^RegZStmntAdj.[A-z0-9_].\.txt$, and I am trying to figure out why it won’t match any of the files in the directory. This is valid syntax if I am thinking correctly.
RegZStmntAdj2_07272011.txt
RegZStmntAdj1_07272011.txt
RegZStmntAdj2_07272011.txxt
New Text Document.txt
If I run the regex with ^RegZStmntAdj.*.\.txt$, it matches the correct files and deletes them. I know * works, but I would like to learn to make more precise Regular Expressions.
RegZStmntAdj2_07272011.txt
RegZStmntAdj1_07272011.txt
Try the following Regex:
I’ve used
\w, which is the same asA-Za-z0-9, and told it to match 9 characters so that it will match the_<date>part of your filename. You were only matching the first character from there (i.e. the underscore).Using Powershell to verify:
To make your regex even more precise, you could use
^RegZStmntAdj\d_[\d]{8}\.txt$, which translates to:which I believe is what you are looking for.