Using RegEx with Replace

Advanced Renamer forum
#1 : 15/02-18 10:17
Mark
Mark
Posts: 170
Kim,

Probably for you, this question ....

Using the Replace method, Guide says "When checked, regular expressions can be used to replace certain patterns of the filenames". I was looking to search for all upper case extensions and replace them with lower case.

Case sensitive: ticked
Use regular expressions: ticked
Apply to: Name and extension

Text to be replaced: \.[A0-Z9]+$ (this finds all upper case extensions)
Replace with ..... ah! whatever I enter, the plain text is used, rather than the result of any RegEx I put in here.

OK, after thinking, I realised it was a dumb way of doing it as RegEx can't invert what it finds, but if I also put \.[A0-Z9]+$ into the Replace with box, I would expect no change to be made. instead, I see the plain text \.[A0-Z9]+$

Is this by design?

Mark

For those interested, you can use AR to filter the added files by using the RegEx \.[A0-Z9]+$ (just loads files with upper case extensions, avoids issue of trying to load too many files, 20000 limit?), then apply the simple New case method, set to lower case.


15/02-18 10:17
#2 : 15/02-18 12:39
Stefan
Stefan
Posts: 264
Reply to #1:
Is that the right expression?

I only know it as     [A-Z0-9]






 

----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


15/02-18 12:39
#3 : 15/02-18 13:53
Mark
Mark
Posts: 170
Reply to #2:
Yes, the RegEx I used is OK, as applied.

The question is, can any, working RegEx be used in the "Replace with" box to give the result of that RegEx? It just seems to get copied as plain text.

Try an example .... use the same RegEx in both boxes .... still, the replacement is plain text.


15/02-18 13:53
#4 : 15/02-18 15:46
Stefan
Stefan
Posts: 264
Reply to #3:
An RegEx replacement is always plain text....
typed-in text or the result of a captured find, like "(.+)- (.+)"


You can't use regex syntax in replacement
other than the backreference signs like \1, \2,. ...


The RegEx expression is to find only.
For to find "certain patterns of the filenames" to replace them.


https://www.advancedrenamer.com/user_guide/regul ar_expresions

- - -

There are additional replacement pattern like \U, \L and \E and some more.
So you could upper case a found pattern like \U\1

But that have to be implemented by the used regex engine
or by additional code by the ARen author, like

"if found '\U', call .toUppercase() function for the backreference group \1".


- - -


You said:
"filter the added files by using the RegEx \.[A0-Z9]+$
(just loads files with upper case extensions, "


Why not do that and then use:

New case method
Upper case
Apply To: Extension
https://www.advancedrenamer.com/user_guide/metho d_newcase



Or was that only a proof of concept ? ;-)
 


----------
If this tool had saved you time, perhaps you want to donate an Dollar to Kim?
See http://www.advancedrenamer.com/download >>> [Donate] button.


15/02-18 15:46 - edited 15/02-18 15:52
#5 : 15/02-18 17:25
Mark
Mark
Posts: 170
Reply to #4:
OK, so a RegEx effectively results is a "yes/no" .... in this case, \.[A0-Z9]+$ identifies files that have upper case extensions.

The RegEx doesn't return the value of that search, ie ".TXT" for instance.

That make sense.

Maybe the GUI should be modified; presently, it's a bit confusing, giving the impression that Regular Expressions can be used for both input boxes.

Thanks,

Mark


15/02-18 17:25
#6 : 01/03-18 10:24
Mark
Mark
Posts: 170
Reply to #5:
OK, I've learnt a bit more about RegEx. Of course it can give the result of a search, you have to use the syntax/approach/code.

You can get the result, in at least a couple of ways:

See http://vim.wikia.com/wiki/Changing_case_with_re gular_expressions

Given xxxxxxxxxxxxx.TXT

Text to be replaced: (\.[A0-Z9]+$)
Replace with: \1
Apply to Name & Extension
Gives .TXT

or

Text to be replaced: \.[A0-Z9]+$
Replace with: \&
Apply to Name & Extension
Gives .TXT

BUT using \L to precede the \1 or \& does not apply a lowercase .....

Is this a bug within AR's RegEx implementation?

Mark


01/03-18 10:24
#7 : 04/03-18 17:47
Kim Jensen
Kim Jensen
Administrator
Posts: 774
Reply to #1:
Why don't you use the New Case method? You can use it to change all extensions to lower case.

You can also use it to change a pattern (using regular expressions) to either lower or upper case.

The \L regular expressions modifier is not supported by the regular expressions implementation used by Advanced Renamer. As far as I know, it is not supported in most implementations of regular expressions.


04/03-18 17:47
#8 : 04/03-18 20:30
Mark
Mark
Posts: 170
Reply to #7:
Hi Kim,

The whole thread was a bit of RegEx experimentation on my behalf :)

As usual, there are many ways within AR to do a certain thing.

Most importantly, I know not to try any further with the \L modifier!

Regards,

Mark


04/03-18 20:30