RegExp Rename (?<=\d)( )(?=\d) > -

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kalle
Posts: 6
Joined: 23 Jun 2014 17:24

RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

Hi all,

i tried to rename file, which contain a date in form yy mm dd (seperated by blanks) into yy-mm-dd without changing other appearing blanks.

So i formed the pattern (?<=\d)( )(?=\d) and tried it in Programmers Notepad and Notepad++, where it worked to find only those blanks with a number before and after.

But when i try (?<=\d)( )(?=\d) > - in the RegExp rename field, it tells me an Syntax Error... :(

Isn't that possible by RegEx in XYPlorer?

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

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by highend »

Welcome to the forum.
Isn't that possible by RegEx in XYPlorer?
Unfortunately, it's not. XY uses vbscript.dll for it's regex engine. It doesn't support lookbehind...
One of my scripts helped you out? Please donate via Paypal

kalle
Posts: 6
Joined: 23 Jun 2014 17:24

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

Thank you for welcoming me and especially for the quick response.

I guess i have to look into scripting xy ... or would you or anyone have another (rather easy) suggestion?

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

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by highend »

Not elegant but should work:

Code: Select all

(\d+) (\d+) (\d+) > $1-$2-$3
Renames e.g.:

Code: Select all

hello 15 10 26 world.txt
into

Code: Select all

hello 15-10-26 world.txt
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by bdeshi »

you can try scripting with xypcre (by me :whistle: ), which supports some advanced regexp ops. However this will be an ugly & convulted process.
something like renameitem(oldname, pcrereplace(oldname, pattern, replacement)); //I'm not sure if the syntax is correct, awayfrompc.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

kalle
Posts: 6
Joined: 23 Jun 2014 17:24

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

Amazing!

Thank's so much.

But now, aside this topic ... can i use $1, $2 as the opening (
like variables in RegEx

on the other hand, i tweaked your line into
(\d{1,2})[ .](\d{1,2})[ .](\d{1,2}) > $1-$2-$3
to allow 1 or 2 digit numbers and a dot or blank as seperator

armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by armsys »

kalle wrote:... can i use $1, $2 as the opening ( like variables in RegEx
What do you mean?
Can you show us some sample text strings and expected results?

kalle
Posts: 6
Joined: 23 Jun 2014 17:24

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

it seems correct:

usage of $1, $2, and so on in renaming into always gives that substring which was found by the regex expression in the numbered brackets ($1) ($2)

That way was my very first attempt, but i was unable to figure the Syntax. How dumb one can think ^^

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

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by highend »

(\d{1,2})[ .](\d{1,2})[ .](\d{1,2}) > $1-$2-$3
You didn't mention that dots are possible separators in the first place :)
One of my scripts helped you out? Please donate via Paypal

kalle
Posts: 6
Joined: 23 Jun 2014 17:24

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

Yes, that's true, i didn't mention dots as possible seperators to keep my question tight and small
Since i'm native german

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

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by highend »

Since i'm native german
My heartfelt sympathy! *feix*
One of my scripts helped you out? Please donate via Paypal

kalle
Posts: 6
Joined: 23 Jun 2014 17:24

Re: RegExp Rename (?<=\d)( )(?=\d) > -

Post by kalle »

highend wrote: *feix*
Danke vielmals *grins*

Post Reply