RegEx question

Hi,

I would like to search files name and do something.  For this I am searching file names using Regex like "[0-9](.).[0-9]{8}[.](.*)[.].txt$" and this value come from INI file.

Some reason some files found that should not find using above mask.  For example "Revised23.20121001.aklldddk.h.txt".  

I like to search files name starting with numeric. I used caret (^) above in my file mask but then no files found.  Is the caret(^) not support?  

Please help.


Thank you.

Jeegs

Which action are you using?

I am using FileSet define action. In this action, I put variable in Filters tab and checked “Use Regular Expression”.

If your fileset is set to store full paths, the ^ will not work since the regex is operating on the full path. Also I would suggest testing your regex first with a regex tool like Expresso. I tried your regex with the above mentioned filename and it didn’t match, as I would have expected.

You didn’t say what version of Automise you are using, the regex engine in AT3 is quite limited, AT4 uses PCRE which is a very good fully featured regex engine.

I am using AZ 4(4.0.0.196).
OK. I wrote wrong Regex above.
My files look like ‘23.20120831.CMU_BCM_01.m.001’ so, I build RegEx in Expresso(Thank you for suggest).
It is like ‘^(\d*).(\d{8})…*.(m|h).001$’. I tried this mask in my INI file and test package but no files found.
How can I use this mask to find files from FileSet Define action?
I am using Path Contains option in Filters and put variable that has this mask and tick on Use Regular Expression.

Thanks
Jeegs

The first thing to do is set the pattern so that it files all files that might match. You cannot use regex there, since the patterns use the window findfirst/findnext api’s which do not support regex, only wildcards. So set the pattern to .001 , then add a Path Contains filter. Use

(\d
).(\d{8})…*.(m|h).001$

For the filter, the regex is matching against the full file path, so you cannot use ^ in the way you are trying to do.

I just tested this exact scenario here and it works as expected.

Vincent,
I follow your above instruction(use pattern to *.001) but did not work for me.
My FileSet Define action found second file(file name starting with “Revised_”). Would you please send me your tested scenario. So, I can match with my and see what I’m missing.

Example:
23.20120831.CMU_BCM_01.m.001
Revised_23.20120831.CMU_BCM_01.m.001

Thanks,
Jeegs

My apologies for the delay in replying, slipped of the radar (a lot going on here at the moment).

The problem is that because the full path is being evaluated (not just the filename), you cannot use ^

however, we know that there is a path separator before the filename, with that in mind, this worked for me :

\(\d*).(\d{8})…*.(m|h).001$

Note the escpaped \ at the start of this regex. With this filter regex I only see 3.20120831.CMU_BCM_01.m.001

HTH

Thank you Vincent. That did the trick.
Appreciate your help.

Jeegs