Regexp Rename - getting double chars at end

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Regexp Rename - getting double chars at end

Post by Papoulka »

I'm trying to add a symbol, for example '~', at the end of a folder name. So I want "Folder" to become "Folder~".

Using Regexp Rename, my command is:

Code: Select all

(.*)$ > $1~
But instead of adding one ~, this adds two, giving "Folder~~".

This also happens with some other symbols and letters I tried.

In contrast, putting the symbol at the front works fine eg. ~Folder.

This is with v15.40.0003, "::fresh" instance.

Bug?

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regexp Rename - getting double chars at end

Post by highend »

This is no bug. It's because your regex may find zero-length matches.

Code: Select all

(.+) > $1~
Is better suited.
One of my scripts helped you out? Please donate via Paypal

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Regexp Rename - getting double chars at end

Post by Papoulka »

Thank you, highend. My regex knowledge is a little too shallow to have figured it out. Though I did check first with RegexBuddy which showed that

Code: Select all

(.*)$ > $1~


should work as I had thought, giving one tilde at the end. The Regex101 website shows the same, in all available flavors. So somehow XY differs on this. May still be a regex engine flavor issue, though it's a surprisingly basic difference if so.

grindax

Re: Regexp Rename - getting double chars at end

Post by grindax »

.
Last edited by grindax on 26 Jan 2016 15:51, edited 1 time in total.

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Regexp Rename - getting double chars at end

Post by highend »

Maybe the best explanation for what and why zero-length matches arise problems:
http://www.regular-expressions.info/zerolength.html

In this case the regex engine finds one match before the string and one after. Hence the doubled ~

The probably most compatible option is: VBscript

Although I've always used PowerGREP 3 & 4
Be careful, VBscripts regex engine doesn't support lookbehinds (which PowerGREP 3 & 4 does)
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Regexp Rename - getting double chars at end

Post by TheQwerty »

grindax wrote:Also, what is the best choice of target application in RegexBuddy when creating regexs for XY?
Select JavaScript then VBScript, and it should be pretty close if not the same.

Regex101 will show the same if you ensure the global modifier is enabled.
https://regex101.com/r/qP7sN7/1


Papoulka, if you really just want to append or prepend I'd avoid the capture and instead use one of:

Code: Select all

^ > ~
$ > ~
Though at that point you might as well just use Batch Rename with:

Code: Select all

~*
*~
Which if you're also working with files is nice since it more easily handles extensions.


Post Reply