PDA

View Full Version : How to escape '[' and ']' in folder filters?


22-Jan-2006, 12:04 PM
I am trying to ensure that only folders with certain markers such as '[Copy]' in the folder name are included, however using a filter like ...\*[Copy]* seems to treat the 'Copy' as a regular expression character. If I use ...\*\[Copy\]* then I get the following error message and BC (2.3.1) locks ups:

"TRegExpr(comp): Unmatched [] (pos 7)"

So how do I escape the '[' and ']' in a folder filter?

chrroe
22-Jan-2006, 01:45 PM
Hi Simon!

I made the following test:

<ul type="square"> Create a folder "test[copy]"
open the parent-folder of it in BC folder viewer
Right-click on "test[copy]" to invoke context-menu and choose "Exclude..."
now the expression "-.\test?copy]\" is added to the filter entry
remove the "-" at the beginning of that entry
... done
[/list]
Looks funny with that question mark. Don't know if it's correct.


Hope this helps


Bye
Christoph

23-Jan-2006, 03:54 AM
Hi Christoph,

Many thanks for the suggestion. It's almost there - the only draw back is that the "?" matches any character of course. I’ve now avoided the issue altogether by renaming all the applicable folders with parenthesises instead.

A small item for the BC enhancement list I think!

Simon

Craig
23-Jan-2006, 12:02 PM
Hi Guys,

The '[' and ']' characters normally mark a range, like [A-Z]. We don't support escape characters, per se, but it turns out you can use '[[]' to escape the '[' character, since that effectively means the any characters in the set '['. The ']' character doesn't have to be escaped since it's only a special character if it ends a range. So, you can use this as the filter: ...\*[[]Copy]*

The ? in the "Exclude" command is correct; it was implemented before I figured out the above (that is, today ;)) and we thought the chances of another file matching the ? as any character besides the [ while still having a trailing ] would be pretty slim. I'll change exclude to use the syntax above in the next release, and we'll consider adding some sort of explicit escape support in a later release.