Page 1 of 1
Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 16:12
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:
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?
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 16:20
by highend
This is no bug. It's because your regex may find zero-length matches.
Is better suited.
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 16:43
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
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.
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 17:27
by grindax
.
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 17:43
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)
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 17:51
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:
Though at that point you might as well just use Batch Rename with:
Which if you're also working with files is nice since it more easily handles extensions.
Re: Regexp Rename - getting double chars at end
Posted: 25 Jun 2015 18:08
by grindax
.