See if a file name matches extended range.

#1
How would I see if a file 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]"

Looked at @wild but that does not fit... Thank you!
 
#4
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...
 

rps

Jul 6, 2008
287
4
#10
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"
.OR.
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.
 
#13
Regex defaults to case sensitive unless you wrap it in a group and add the ignore case option.
Code:
\w\.jpg(?i:MA)\d{8}_\d{3}\.\d{3}
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.
Code:
\w\.jpg(?i)MA\d{8}_\d{3}\.\d{3}
\w\.jpg(?i)MA(?-i)\d{8}_\d{3}\.\d{3}
 
Last edited:

rps

Jul 6, 2008
287
4
#14
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.