Seaching for a folder via scripting: regular expression problem

Started by ubacher, February 20, 2018, 02:38:54 AM

Previous topic - Next topic

ubacher

I am trying to search for a folder starting with the following:
D:\Foto Cache\2014-10-18

I use:
IMWS.get('v1/folders', {
  regexp: 'path,' + 'D:\\Foto Cache\\2014-10-18'

which returns an illegal reg exp error.

If I put instead: 'D:.{1}Foto Cache.{1}2018-01-31'    
it works.

A Bug? or am I doing something wrong?

Mario

Make sure you are escaping all characters which have a special meaning in regular expressions.
See the Perl Regexp references listed in the IMatch help for details.

Note: You are receiving email notifications from the community, but your mail server is bouncing all emails, filling my inbox.
Please ensure that you can receive emails from @photools.com (ask your ISP) or disable email notifications. If your ISP is blocking emails without you knowing, he has basically taken over your inbox and some AI decides which emails you get, and which not...
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

QuoteMake sure you are escaping all characters which have a special meaning

backslash is a special character. If, however, I escape it i.e. \\ then I get the error message that it is
an illegal expression. Why?

Not accepted: D:\\Foto Cache\\2014-10-18

Accepted: D:.{1}Foto Cache.{1}2018-01-31
( where I have put .{1} just to pin down where the error is}

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

I tried it on: regex101.com

it takes the ":" as literal.

and it finds D:\\Foto Cache\\2014-10-18 as correct.

Mario

Make sure you are using a PERL regexp tester, not one of the others.
I have no deeper knowledge about regexp and I can't debug this for you, sorry.
I only work here and when the Boost RegExp parser tells IMatch that the regexp is invalid, I return that result to your app.

I have currently no IMatch working so I cannot try this out my self. Open a bug report if you think that IMWS is wrong so I can schedule time for a later test.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mario

The Perl docs say:

https://perldoc.perl.org/perlrebackslash.html

If the character following the backslash is an ASCII letter or an ASCII digit, then the sequence may be special; if so, it's listed below. A few letters have not been used yet, so escaping them with a backslash doesn't change them to be special. A future version of Perl may assign a special meaning to them, so if you have warnings turned on, Perl issues a warning if you use such a sequence. [1].

So you cannot simply use \\ when it is followed by an ASCII character. See the doc page above for all details.
If you want to match a full path, use the path parameter instead.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

I found the problem:
In javascript one has to escape the \ also, thus I had to double the escaping:
instead of D:\\Foto Cache\\2014-10-18
I needed
D:\\\\Foto Cache\\\\2014-10-18

to do this automatically I then used
rootFolder.replace(/\\/g, '\\\\')

I knew about the need to escape in javascript and also the need to escape in reg-exp but I never put both together. Learned something.
I hope this will help others, otherwise I apologize for taking your time.

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook