admin wrote:
It might be easy... please RegExp fans, give some examples of Boolean RegEx search patterns (including short explanations what they do) you would like to apply! I need them for tests...
This should be very easy to implement. The primary steps are:
1. You need a way of delineating each RegEx pattern so that it's easy to discern what is part of a RegEx and what is not. You can surround each RegEx pattern in quotes, but the problem is what happens if someone wants to search for quotes. I think the best solution here is the same one you used for the RegEx Rename seperator - put a line in the INI file that lets people choose their own delineator (which can be more than one character - such as "**". That would be used like this: **Test RegEx Pattern**) and show them what it's set to in the dialog box.
2. Design it so that any parenthesis used *outside* of delineated RegEx patterns can be used for grouping (Remember not to make this sweeping, since parenthesis can be used in a valid RegEx as well). For example: "Pattern 1" AND NOT ("Pattern 2" OR "Pattern 3")
2. Evaluate each RegEx pattern seperately, and keep track of the resulting list of matches for each.
3. Apply the Boolean logic used, if any.
So, for the example below, which uses the "AND NOT" operator, you would evaluate both patterns, and remove the results from the second pattern from the results of the first.
Remember that a Boolean RegEx might contain more than two RegEx's.
So, since one of the most useful features of Boolean RegEx is the NOT operator, here's an example...
Design:
Match all file names that have:
1. The word "test" anywhere in the file name.
2. Exclude any lines where the word "not" precedes the word "test" at any distance (i.e. it doesn't have to be right next to it). Lines that have the word "not" *after* the word "test" are acceptable to match.
Boolean RegEx (Delineator used: double quote):
Pattern:
"Pattern 1" AND NOT "Pattern 2"
Code: Select all
".*test.*" AND NOT ".*not.*test.*"
Test Data:
--------------------------------------------
Testing 3, 2, 1.doc
Some random file.txt
This is not a test.avi
.Test.txt
Test of this RegEx Pattern.xls
Not a random file.txt
This is a valid test.exe
Ignore me, I'm just here for show.avi
File that is not a good test.com
This is a good test, not a bad one.exe
--------------------------------------------
Correct Results:
--------------------------------------------
Testing 3, 2, 1.doc
.Test.txt
Test of this RegEx Pattern.xls
This is a valid test.exe
This is a good test, not a bad one.exe
--------------------------------------------
Notes:
I've used the double quote as the RegEx delineator, but something like "**" would probably be much better, as it's far less likely to see that in a RegEx than a double quote. But make this adjustable the way you did the RegEx Rename seperator, and all will be well.
Also, XY has some strange behavior when using RegEx Rename, and the find pattern is ".*" - in any form (e.g. ".*" or "(.*)", etc...). It causes duplicate looping in the renamed file. It is corrected by prefixing the ".*" in whatever form it's in with a "^" to signify the beginning of a line. So "^(.*)" or "(^.*)" or "^.*" all work fine. It's not a big deal, because it has an easy workaround - but you should be aware of it when you are doing RegEx testing, since you may get incorrect results with a perfectly valid RegEx, if it falls into this scenario.
I'll post some additional examples later. I hope this helps! And thank you for looking into this now.
