See if a file name matches extended range.

Apr 2, 2011
North Carolina, USA
How would I see if a file matches:


Looked at @wild but that does not fit... Thank you!
for %fn in (*) if %fn matches "*.jpgMA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9].[0-9][0-9][0-9]" move "%fn" destination....
I could use @right[3,%fn] and see if that is a number, then test other substrings to see if they match the pattern but I'd rather do one test - one function call...
Can't you change the grouping instead?
do fn in *.jpgMA[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9].[0-9][0-9][0-9] (move "%fn" destination....)
Look at the peseucode for the otherwise part of the switch statement in [:SelectPathForType] in the attached BTM...


  • MoveAll.BTM
    16.5 KB · Views: 166
You could use @REGEX.
if %@REGEX[".*\.jpgMA\d\d\d\d\d\d\d\d_\d\d\d\.\d\d\d",%sName] == 1 set sTargetSubDir=My Images
The expression I posted matches your wildcard filename. But if you want to play with regular expressions use the regex dialog. Ctrl+F7 or REGEX at the prompt.
I know TCC/TCMD has a regex analysier / tester - but any documentation on constructing one?

Also thank you very much @samintz
Open the Tcmd/TCC Help file
search for "@regex"
under the @regex help there is a link to "Regular Expression Syntax"
search for regular expression syntax
scroll down in the Select topic: window and choose Take Command/TCC Regular Express....

When I do this search the 6th topic is what I am looking for. I added this to my Favorites tab for future reference.

This should assist you in constructing a regular expression.

You could also try: "\w\.jpgMA\d{8}_\d{3}\.\d{3}" assuming the name before the 1st '.' has no special characters. The numbers are inside curly brackets.

There are obviously other ways to construct a Regex that only requires the filename with any combo of digits before and/or after the underscore "_". But based on what I understand from the OP the above should work.
Regex defaults to case sensitive unless you wrap it in a group and add the ignore case option.

Edit: See 7. Extended groups in the Regular Expression Syntax of the help file.

Edit 2: You can also precede the specific section (or entire expression) with the option to apply it to all following text without enclosing the desired text within the group. You can then turn ignore case off again.
Last edited:
Looking over the CHM reg exp help - I don't see a way to test if the MA are both uppercase?
The way the Regex is currently written means MA is uppercase.
Did you try using lower case letters, say Ma, is your file name. If you do the current Regex shouldn't match foo.jpgMa..... since the expression is specific to MA, all caps.

If you need to match MA, Ma, ma, or mA then add (?i), meaning case insensitive, to the Regx before the MA string.
Example: Regex \w\.jpg(?i)ma\d{8}_\d{3}\.\d{3} will match foo.jpgmA12345678_123.123

BTW, this was not in the TCC syntax docs. Found this info on-line somewhere. :happy:

Ah! didn't see that until JohnQSmith pointed it out. Thanks.
In addition to extended groups, you can turn case-insensitivity on (with "(?i)") and off (with "(?-i)"). The two may be equivalent, and the extended group is a tad easier.

Similar threads