#1 2007-12-05 18:35

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Delete last part

Hi,

I try to do something, but no way to find.

Let's say that I have this kind of files:
"title.text1.text2.extension"

but I also can have this:
"title.text1.text2.text3.extension"

What I want to do it is to delete the last part behind the dot (without the extension).

So my result will be:
"title.text1.extension" for "title.text1.text2.extension"
"title.text1.text2.extension" for "title.text1.text2.text3.extension"

Please, somebody help me !!!! hmm


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#2 2007-12-05 22:45

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Delete last part

Hi ozzii,

you could catch this with regular expression:

Find all till the second last dot     ==> (.+)\..+\.ext


So add an RegEx Rule
Expression:     (.+)\..+
Replace:          $1
[x]  Skip Extension


This means
.       ==> an dot find one char, no matter which
+     ==> find one or as many (greedy) of the same kind as the char before (any char in our case)
()     ==> group this to refer back to this find later
\.     ==> escaped dot, to find an dot by it self (and not "any char" as above)
.       ==> an dot find one char, no matter which
+     ==> find one or as many of the same kind as the char before (any char in our case)

$1    ==> replace whit them found in expression group one
       ==> we didn't replace the rest..... so this is deleted


Note:
Greedy means "find/catch as many as you can" .... till the last dot in our case.
Try (.+?)\..+  where the ?-sign means "be non-greedy" and you will find all till the first found dot only.



HTH?
Stefan


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2007-12-06 06:10

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Delete last part

Thanks Stefan.
I will test it this afternoon. So I will tell then if all is OK roll

Thanks.
P.S: I will love to know to use (a little more) RegEx wink

EDIT:
It's working !!! Thanks a lot

Last edited by ozzii (2007-12-06 07:42)


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#4 2007-12-06 07:36

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Delete last part

One more question (for Stefan maybe).

How I can do to delete all the end of the name after the latest digit.

For example I can have:
text.100.text2.text3.text4.extension
text.text2.100.text3.text4.extension
text.100.101.text3.text4.extension

For result I will have:
text.100.extension
text.text2.100.extension
text.100.101.extension

Thanks in advance.


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#5 2007-12-06 08:25

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Delete last part

You are welcome. Great it works.

ozzii wrote:

How I can do to delete all the end of the name after the latest digit.

You have to find someone common in the file names.



For example I can have:
text.100.text2.text3.text4.extension
text.text2.100.text3.text4.extension
text.100.101.text3.text4.extension

Here you want to find an digit.
Then split your file name into parts:

ALL - Digit - Remnant.ext

To find any char use the RegEx .    (an dot)
To find all use the RegEx .+
To find one digit use \d
To find one or more digits use \d+

To back referencing later to this find you have to group the search by ()
To find all use the RegEx (.+)
To find one or more digits use (\d+)
Later you are able to get what your RegEx have found back by using an $1 for the first group, an $2 for the second,...


So try
Expression:  (.+)(\d+)
Replace:       $1$2

-----------------

This didn't works ... you have to catch the hole file name:
To find the remnant use .+ again

So try
Expression:  (.+)(\d+).+
Replace:       $1$2

(since we didn't need the remnant after the digits later... we don't need to group this)

-----------------

This didn't works ... the first .+ is to greedy. Use an ?-sign to be non-greedy

So try
Expression:  (.+?)(\d+).+
Replace:       $1$2

-----------------

For result I will have:
text.100.extension
text.text2.100.extension
text.100.101.extension

Thanks in advance.

I have no time right now to test this much, but i think this should work.

CY
Stefan


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2007-12-06 08:32

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Delete last part

YES !!!!! lol big_smile

This is it.
I was trying when you post your answer.

THANKS !!!! This is a really big help (for me at least) cool

PS: With your explanation, I begin to understand a little more RegEx.


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#7 2007-12-07 13:39

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Delete last part

Good man, Stefan! I appreciate your help with answering questions on forums! smile

Ozzi, just wanted to recommend a good place to learn RegEx: http://www.regular-expressions.info/

Offline

#8 2007-12-07 14:05

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Delete last part

Stefan (or someone else) , one more question.

When I have a filename (without the extension) who ended with a digit, last digit is deleted.
I try but with no success; is there a way to not lose the latest digit in this case?

Thanks again.


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#9 2007-12-07 14:15

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Delete last part

Can you post the exact RegEx expressions that you are using?

And few sample filenames, which do work, and which don't.

Offline

#10 2007-12-07 15:38

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Delete last part

Here it is wink

071207-15.34.43.jpg


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

Board footer

Powered by FluxBB