Problem with marking files by pattern / RegEx

Advanced Renamer forum
#1 : 22/10-20 03:41
Eric
Eric
Posts: 4
Hello!
I'm sorry, but I could not find a solution to my problem anywhere and I am at my wit's end...

I have a folder with a large amount of random image files. These files follow multiple naming schemes (some filenames are exactly 15 characters long, some 13, others are combination of words and numbers separated by underscores etc.). The list looks something like this:

1111111.jpg
2222222.png
33333333333.jpg
4444444.jpg.
abc_1234.jpg
55555555555.jpg

Since these files all need to be renamed differently, I want to mark groups of files in the file list according to their name patterns, like: "Mark all files with exactly 7 characters" or "Mark all files with three word characters followed by an underscore" etc.

I tried using the "Mark by pattern" option, but I cannot figure out how to use it properly. Either I get no result or the error message "A regular expression specified in RegEx is required".

Could someone please explain how to use that option or show me a guide or the like?

Thank you very much in advance!

E


22/10-20 03:41
#2 : 22/10-20 12:51
David Lee
David Lee
Posts: 1125
Eric

You should be able to work this out from information in the User Guide:
www.advancedrenamer.com/user_guide/regular_expresions

I assume that you are using the "Add Directory" Add method and you are entering your regex in the "Regular expression match:" box.

To match filenames with exactly 7 characters use the regex: ^.{7}\.
^ = Start of Filename
.{7} = match any 7 characters
\. = match "."

note that "." on its own represents "any character", adding the prefix "\" cancels this special meaning so that the "escaped" character represents itself

To match all filenames beginning with three word characters followed by an underscore use:
^[a-zA-Z]{3}_

Here [a-zA-Z] will match any character represented inside the square brackets - ie characters in the range a-z or A-Z (based on their ASCII codes ).

Note that the metacharacter \w is supposed to represent any word character or "_", however there appears to be a bug in ARen's implementation of PCRE so that \w will also match decimal digits.

There is enough information in the User Guide to get you started with regular expressions - however it only gives a very small sub-set of the available syntax so you will need to search online for more advanced solutions. Note that there are several differing regex implementations - the one used by ARen is "Perl Compatible" (PCRE).

Finally, you can use regular expressions in most renaming methods so it is likely to be a better solution to load ALL your files into the list and use regex in the methods to selectively rename them. If the requirements are too complex then you can do almost anything using the Script method. However if you are new to JavaScript that will involve another steep learning curve and is likely to require the use of regex - so take it one step at a time!


22/10-20 12:51 - edited 22/10-20 19:06
#3 : 22/10-20 22:51
Eric
Eric
Posts: 4
David,
thank you so much for your patient, fast and thorough answer und explanation. The time and effort you put into it is way more than I had hoped for, and I appreciate it very much.

As for my question: The solution you described works like a charm. I did not think of trying to filter the files before adding them to the AR file list (and now I think I finally understand how to use the ^). The method I tried before was to add the whole directory, unmark all the files und then "Mark by Pattern" from the right click menu. But no matter what expression I tried, I always only got an error message and thought that this marking method requires more than just the expressions I could handle ("A combination of tags and expressions perhaps?", I thought). Using this list would have been more comfortable, but filtering files directly while adding them is just as good. I think I will be able to finish the renaming process with the methods you described.

Again, thank you very much, stay healthy and have a nice day!

Eric

*Edit: I think I found the root of the problem. I only get an error message when using AR version 3.84 and above. In version 3.83 and below, "Mark by Pattern" works as I expected it to.


22/10-20 22:51 - edited 23/10-20 05:36
#4 : 23/10-20 10:29
David Lee
David Lee
Posts: 1125
Reply to #3:
Reply to #3:


Reply to #3:

Hi Eric

I have come to the same conclusion - Mark by pattern is broken. The pattern entered is not being read - if you enter a plain text pattern and select "Mark not matching pattern" then all files will be selected.

I'll ping an email to Kim to report the issue.

To be honest I wasn't aware of the marking functionality as it isn't documented in the User Guide, which was why I assumed that you were selectively importing the filenames.

As I said, a neater way of approaching the problem is to import ALL your files into the list and then selectively rename using a script. For example try this script on your example filenames:

name = item.name;

if (name.search(/^.{7}$/) > -1) {
name = app.parseTags("File <Inc Nr> (7 char)");
return name;
}

if (name.search(/^[a-zA-Z]{3}_.*/) > -1) {
name = app.parseTags("File <Inc Nr> (abc_)");
return name;
}

In this example name.search(str) will look for an instance of the search string "str" in the string "name" and return its position in the string. If not found then it will return -1.

You can use regular expressions as the search string but you must enclose the regex between "/" characters instead of the usual quotes.

There is a very basic introduction to scripting in the User Guide but you will need to search the Internet for more help. Search for JavaScript and suitable keywords - eg "javascript search". I have learnt most of my JavaScript in this way - particularly using hits at www.w3schools.com

It's quite a steep learning curve - but this means that you will rapidly make progress even though it will be pretty confusing at first.

David


23/10-20 10:29
#5 : 23/10-20 12:05
Sailor Guy
Sailor Guy
Posts: 40
Everyone,

One of my work buddies shared this link with me when I was working through some regular expression issues.

This is a great resource!

www.regex101.com

Enjoy!

Sailor Guy


23/10-20 12:05
#6 : 23/10-20 12:59
David Lee
David Lee
Posts: 1125
Reply to #5:
My favourite resource is www.regular-expressions.info


23/10-20 12:59
#7 : 23/10-20 13:48
Sailor Guy
Sailor Guy
Posts: 40
Reply to #6:

Thanks, David!

I've added the web site to my "Useful Web SItes" list!

Sailor Guy


23/10-20 13:48
#8 : 23/10-20 17:56
Eric
Eric
Posts: 4
Reply to #4 - 7:
Hi everyone!
Thanks for the java script examples! I will look into that, maybe even dig into java script as a whole (having no experience with scripting). Those links look helpful!

Again, thanks for the help and advice and resources!

Eric


23/10-20 17:56
#9 : 25/10-20 10:00
David Lee
David Lee
Posts: 1125
Reply to #8:

Eric

Just in case you are still following this thread...

I have received a reply from Kim and "Mark by pattern..." will be fixed in the next version of the program (3.88).

Also my comment regarding the regex meta-character \w was incorrect. The definition of a "word character" is any alphanumeric character or "_" - ie \w includes numeric digits.

So \w equates to [a-zA-z0-9_] and the error is in the Advanced Renamer User Guide not the program.

David


25/10-20 10:00
#10 : 25/10-20 13:05
Eric
Eric
Posts: 4
Reply to #9:
Hi!
I'll be looking forward to 3.88 then. Thanks for the heads up and the \w clarification!


Eric


25/10-20 13:05