Page 1 of 3

Boolean RegEx

Posted: 14 Oct 2008 20:29
by Mesh
I love that XY supports RegEx in its various functions, such as File Find, Display Filters, etc...

However, there is one enhancement that I have found myself frequently wishing for, and that is Boolean RegEx.



I would love the ability to do something like this:

Code: Select all

(<<RegEx Pattern>> AND <<RegEx Pattern>>) OR (<<RegEx Pattern>> AND <<RegEx Pattern>> NOT <<RegEx Pattern>>)
Note: I'm using "<<" and ">>" to clearly delineate the boundries of each RegEx pattern, so that the boolean operators and grouping parentheses don't get confused as part of the RegEx.


There are many searches that can only be done through RegEx, and many results that can only be obtained by applying boolean logic - so it seems ideal to be able to combine them. This would allow functionality that I don't think is possible right now any other way.

Re: Boolean RegEx

Posted: 14 Oct 2008 21:05
by admin
I see your point, but the timing is bad. :) And it's partly your own fault. :P After spending most of the year on power user features like scripting and techno stuff like unicode support, I decided to waste the rest of the year on popular stuff for the common man! This will include Dual Pane, tabwise history, Undo and similar groovy things.

Re: Boolean RegEx

Posted: 14 Oct 2008 21:13
by serendipity
admin wrote:I see your point, but the timing is bad. :) And it's partly your own fault. :P After spending most of the year on power user features like scripting and techno stuff like unicode support, I decided to waste the rest of the year on popular stuff for the common man! This will include Dual Pane, tabwise history, Undo and similar groovy things.
Wow!! Good idea. Looking forward to tabwise history and Undo.

Re: Boolean RegEx

Posted: 14 Oct 2008 21:14
by ivan
admin wrote:I see your point, but the timing is bad. :) And it's partly your own fault. :P After spending most of the year on power user features like scripting and techno stuff like unicode support, I decided to waste the rest of the year on popular stuff for the common man! This will include Dual Pane, tabwise history, Undo and similar groovy things.
I wonder what the ratio of common man to power user is here and whether a common man would pick up XY instead of settling for WE. I can sniff another poll coming... :D

Re: Boolean RegEx

Posted: 14 Oct 2008 21:18
by admin
ivan wrote:
admin wrote:I see your point, but the timing is bad. :) And it's partly your own fault. :P After spending most of the year on power user features like scripting and techno stuff like unicode support, I decided to waste the rest of the year on popular stuff for the common man! This will include Dual Pane, tabwise history, Undo and similar groovy things.
I wonder what the ratio of common man to power user is here and whether a common man would pick up XY instead of settling for WE. I can sniff another poll coming... :D
Okay, okay, let me correct my statement: "popular stuff for the " . quote("common man") . "!";

Re: Boolean RegEx

Posted: 14 Oct 2008 21:45
by Mesh
admin wrote:
I see your point, but the timing is bad. :) And it's partly your own fault. :P After spending most of the year on power user features like scripting and techno stuff like unicode support, I decided to waste the rest of the year on popular stuff for the common man! This will include Dual Pane, tabwise history, Undo and similar groovy things.

Oooo, you do make a compelling case! And I will take responsibility for my part. :D

Maybe you'll consider putting this one on your list of power features to implement when you next get around to them? :)

Re: Boolean RegEx

Posted: 15 Oct 2008 01:31
by j_c_hallgren
ivan wrote:I wonder what the ratio of common man to power user is here and whether a common man would pick up XY instead of settling for WE. I can sniff another poll coming... :D
i think the features that Don listed will be of use to both common and uncommon users! And increasing the general user base may likely be easier by these features than attracting new power users with more new exotic items, so I fully understand the reasoning for doing so.

Re: Boolean RegEx

Posted: 15 Oct 2008 02:25
by ivan
j_c_hallgren wrote:i think the features that Don listed will be of use to both common and uncommon users! And increasing the general user base may likely be easier by these features than attracting new power users with more new exotic items, so I fully understand the reasoning for doing so.
Oh yes, I understand the reasoning as well and the more users of XY, either common or power, the better. I just hope that amongst those things we will have XY's own copy/move or I wouldn't be surprised that new common folk who have Vista may bring this topic up http://www.xyplorer.com/xyfc/viewtopic.php?f=2&t=2810 and, considering the last user control (aka new address) bar is now removed, I'm feeling optimistic.

Re: Boolean RegEx

Posted: 15 Oct 2008 02:34
by j_c_hallgren
Yes, I'll agree that new users may create more attention for some "issues", at least for a while, but that may be helped by the sequence in which some of the roadmap items are addressed...there appear also (to me anyway) to be some less complex items which might be done as a group and thus hit more targets with less ammo.

Re: Boolean RegEx

Posted: 02 Nov 2008 06:26
by Demset
Oh, please count me in on this! It would make my file management tasks SO much easier!

I would love to see this one added - sooner, rather than later. :mrgreen:

Re: Boolean RegEx

Posted: 02 Nov 2008 06:40
by serendipity
Demset wrote:Oh, please count me in on this! It would make my file management tasks SO much easier!

I would love to see this one added - sooner, rather than later. :mrgreen:
Welcome to the Club!
While I am sure this feature would definitely come (considering its powerfulness), I am not so sure if it will come soon because of other popular stuff in the pipeline. But admin (aka Don) is known for his quick coding skills, maybe he decides to do it in anyway. :lol: . So stay put and take time to explore this forum and the amazing XYwiki.

Re: Boolean RegEx

Posted: 02 Nov 2008 10:26
by admin
serendipity wrote:
Demset wrote:Oh, please count me in on this! It would make my file management tasks SO much easier!

I would love to see this one added - sooner, rather than later. :mrgreen:
Welcome to the Club!
While I am sure this feature would definitely come (considering its powerfulness), I am not so sure if it will come soon because of other popular stuff in the pipeline. But admin (aka Don) is known for his quick coding skills, maybe he decides to do it in anyway. :lol: . So stay put and take time to explore this forum and the amazing XYwiki.
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...

Re: Boolean RegEx

Posted: 02 Nov 2008 16:22
by Mesh
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. :)

Re: Boolean RegEx

Posted: 02 Nov 2008 16:59
by Mesh
Mesh Example 2:


Design:


Match all file names that have:

1. A numeric formatted date such as mm-dd-yyyy or yyyy-mm-dd. Allow for the presence or absence of leading zeros, but assume a four digit year.

2. The word "budget"

3. Exclude any files that have the word "accounting" anywhere in the file name.



Boolean RegEx (Delineator used: double quote):


Pattern:

(("Pattern 1" OR "Pattern 2") AND "Pattern 3") AND NOT "Pattern 4"

Code: Select all


((".*\d{4}-\d{1,2}-\d{1,2}.*" OR ".*\d{1,2}-\d{1,2}-\d{4}.*") AND ".*budget.*") AND NOT ".*accounting.*"



Test Data:

-----------------------------------------------------

2008-09-23 - Budget Report.xls
Accounting Budget - 2007-11-03.xls
Employee List.xls
Expense Budget - 12-1-2006 through 2-7-2008.doc
General Budget Requirements.doc
Invoice - 12-1-2006 through 2-7-2008.doc
March Ad Proposals.doc
Project Summary - 1-14-2007.doc
Sri Lanka site plans.cad

-----------------------------------------------------



Correct Results:

-----------------------------------------------------

2008-09-23 - Budget Report.xls
Expense Budget - 12-1-2006 through 2-7-2008.doc

-----------------------------------------------------

Re: Boolean RegEx

Posted: 02 Nov 2008 20:20
by admin
Thanks for the examples!

Actually I was thinking of adding just a tiny little thing to the already existing Boolean syntax: Prefix ">" to a Regexp pattern. That way one could freely combine RegExp and normal wildcard patterns in a easy fashion.

Your example would look like this with 2 regexp patterns:

Code: Select all

:>.*test.* AND NOT >.*not.*test.*
Like this with 1 normal and 1 regexp pattern:

Code: Select all

:test AND NOT >.*not.*test.*
Like this with 2 normal patterns:

Code: Select all

:test AND NOT not*test