#1 2009-07-23 17:16

ehamiter
Member
Registered: 2009-07-23
Posts: 1

Regular expressions frustration! Simple solution, I think...

Hi there. The program is great, but the problem is my brain. It doesn't work with regex's.

This is what I'm trying to do:

Rename a folder full of pdfs titled (First name Middle initial Last name):

Bob Q. Smith.pdf
Jack B. Jones.pdf
Sue L. Wilson.pdf

etc.. to Last name First name Middle initial, like this:

Smith Bob Q.pdf
Jones Jack B.pdf
Wilson Sue L.pdf

any suggestions? Thanks!

Offline

#2 2009-07-23 21:57

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Regular expressions frustration! Simple solution, I think...

You can use dot as the "to-find" point.

regex: ([^.]+)\.\s(.+)                  or      ^([^.]+)\.\s(.+)$
replace: $2 $1

Remember to have skip extention on.


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#3 2009-07-25 08:42

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

Re: Regular expressions frustration! Simple solution, I think...

ehamiter wrote:

Rename a folder full of pdfs titled (First name Middle initial Last name):

Bob Q. Smith.pdf
Jack B. Jones.pdf
Sue L. Wilson.pdf

etc.. to Last name First name Middle initial, like this:

Smith Bob Q.pdf
Jones Jack B.pdf
Wilson Sue L.pdf

Hi ehamiter, welcome.

Here i have made krtek tipp more simple to understood by simplify the regex:

Add new rule, chose RegEx:
  Expression:   (.+)\. (.+)
  Replace:        $2 $1
  [x] skip extension



Explanation:
.        means any char
+       means one or more
\.       means find dot itself

So (.+)\. means find one or more chars till an dot is found (ReNamer is non-greedy and stops at first dot found)
Then i search for an blank and then for the rest of the name with (.+) again.


HTH?


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

#4 2009-07-25 12:22

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Regular expressions frustration! Simple solution, I think...

Stefan wrote:

(ReNamer is non-greedy and stops at first dot found)

mmm... sorry but... my experience is not that.

to stop in the first dot I must write "(.+?)\. (.+)"

roll


If this software has helped you, consider getting your pro version. :)

Offline

#5 2009-07-25 20:55

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Regular expressions frustration! Simple solution, I think...

Stefan, it would be quite weird if the + were non-gready in ReNamer as I suppose  it is described as greedy in regex's specification.

I use a repetition of "any sign but not a dot" ([^.]) as it is more specific.  It allways stops on the first dot no matter if you use greedy + or non-greedy +?.

Last edited by krtek (2009-07-25 21:01)


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#6 2009-07-25 23:54

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

Re: Regular expressions frustration! Simple solution, I think...

Of course you are right!

It was an false assuming of me at this time.
This behaviour has nothing to do with RegEx but just in this simple file names
there are one dot only since i opt "skip extension" and that was the whole trick.

regex.png

For this example file names above my simple solution works well enough that's why i provide it.

Thanks for clarifying guys. ReNamer works as expected.


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

Board footer

Powered by FluxBB