#1 2011-06-28 03:28

Rusherman
Member
Registered: 2011-06-02
Posts: 8

Looking for help with another Regular Expression I think

I have been finding some files that have been put in library order for some reason. Maybe a program did it automatically.

A file with a name like "John Doe - The text file.doc"  becomes "John Doe - Text File, The.doc" Or "John Doe - A Text File.doc" becomes John Doe - Text File, A.doc" or "John Doe - An Ideal Text File.doc" becomes "John Doe - Ideal Text File, An.doc". There may be a few more One and two letter words that get shipped to the back that I have not noticed yet.

Is there a way of using a Regular Expression to put this back to original name. If the small expression are the last letters at the end of the file name and before the .extension I would like it cut and put in following the - here again. There are a fair amount of these files and at the moment I am redoing each one annually.

Thank you for listening.

Offline

#2 2011-06-28 06:07

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

Re: Looking for help with another Regular Expression I think

Hi Rusherman.

You can try ReNamers excellent Rearrange rule => see our wiki > http://www.den4b.com/wiki/ReNamer:Rules:Rearrange

Test the following with some copies of your real files.

Tip:
apply the above rule, then open "Options > Analyze Sample Text"
and paste in your example strings and you will see what happens.

Note that that solution may only works for the examples you have provided.




FROM:
John Doe - Text File, The
John Doe - Text File, A
John Doe - Ideal Text File, An

TO:
John Doe - The Text file
John Doe - A Text File
John Doe - An Ideal Text File

DO:
1) Rearrange: Split by delimiters "- |, " ---- New pattern "$1- $3 $2" (skip extension)

This delimiters are: hyphen,space | coma,space
The pipe "|" is an delimiter of the Rearrange rule itself.


(Note: you may need to download the beta first to get this rule?)



So we split at the hyphen and the coma the string into three parts.

This will give you for
John Doe - Text File, The.doc

$1 = "John Doe "
$2 = "Text file"
$3 = "The"

Then just rearrange the output order and add some signs like space or hyphen your own as needed.




Thanks to Denis for that wonderful rearrange rule and making ReNamer at all.



If ReNamer helps you a lot,... please see my footer below.

.
.


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 2011-06-28 17:10

Rusherman
Member
Registered: 2011-06-02
Posts: 8

Re: Looking for help with another Regular Expression I think

Thank you for the advice. I grabbed the new Beta version on renamer and there it was, "Rearrange". The pattern you suggested also works great for the file names I mentions. Since then I have found some with two dashes though. Such as Joe Doe - Series 01 - File Name, The.Doc.

I have tried setting up Rearrange from right to left so that it would not matter if there were extra leading dashes but so far have not had much success. I either lose the final bit or it is put on behind the first dash as in Such as Joe Doe - Series 01 - File Name.Doc. or Such as Joe Doe - , The Series 01 - File Name.Doc.

I make this all sort of messy. I am checking the Wiki page and there are all kinds of choices. I just need to find the right combination.

Offline

#4 2011-06-29 10:23

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

Re: Looking for help with another Regular Expression I think

The other way is RegEx.
Try with: Replace expression " - ([^-]+), (\w+)$" with " - $2 $1" (skip extension)

---
To Stefan: I tried with " - (.*?), (\w+)$" and didn't work the same. Isn't it strange for you too?


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

Offline

#5 2011-06-29 11:50

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

Re: Looking for help with another Regular Expression I think

SafetyCar wrote:

---
To Stefan: I tried with " - (.*?), (\w+)$" and didn't work the same. Isn't it strange for you too?

I think not

because your " - (.*?)" can match any amount of hyphen too, after an first found hyphen.
" - " ===> match space/hyphen(first found because there is any expression missing in front me think)/space
".*?" ===> match none-or-more of any sign, non-greedy, but can match an hyphen too.

Test:
RegEx: Replace expression " - (.*?), (\w+)$" with " - [$1] [$2] [$3] [$4]" (skip extension)
Joe Doe - Series 01 - File Name, The.Doc
Joe Doe - [Series 01 - File Name] [The] [] [].Doc


>"because there is any expression missing in front "
Tip: try always to match the whole string, not only parts. Even the use of ^...$ should mandatory (  big_smile note to myself ;-) )

-


You may want to use:
"(.+) - (.*?), (\w+)$"
"(.+) - "  ===> match one-or-more sign greedy ,incl. hyphens, till the LAST space/hyphen/space
"(.*?),"  ===> match the rest till an coma


Test:
RegEx: Replace expression "(.+) - (.*?), (\w+)$" with "[$1] [$2] [$3] [$4]" (skip extension)
Joe Doe - Series 01 - File Name, The.Doc
[Joe Doe - Series 01] [File Name] [The] [].Doc



This is because the expression match greedy by default.
Test by try non-greedy first part:
"(.+?) - (.*?), (\w+)$"
Joe Doe - Series 01 - File Name, The.Doc
[Joe Doe] [Series 01 - File Name] [The] [].Doc


- - -


Whereas your " - ([^-]+)" means exactly "match after last hyphen"
" - " ===> match space/hyphen (the only one or the LAST)/space
"[^-]+" ==> one-or-more of any sign, but an hyphen.


Test:
RegEx: Replace expression " - ([^-]+), (\w+)$" with " - [$1] [$2] [$3] [$4]" (skip extension)
Joe Doe - Series 01 - File Name, The.Doc
Joe Doe - Series 01 - [File Name] [The] [] [].Doc




- - -

But i think Rusherman have to sort his files into one with one, two (, or even more) hyphen, because i think there is no single rule to match all occurrences?.

Or someone will write him an PascalScript to check each FileName (one-after-one) on the amount of hyphens and reorder the file name parts accordantly.

-


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 2011-06-29 15:06

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

Re: Looking for help with another Regular Expression I think

Stefan wrote:

I think not

because your " - (.*?)" can match any amount of hyphen too, after an first found hyphen.
" - " ===> match space/hyphen(first found because there is any expression missing in front me think)/space
".*?" ===> match none-or-more of any sign, non-greedy, but can match an hyphen too.

Not sure, but might be...

Stefan wrote:

Tip: try always to match the whole string, not only parts. Even the use of ^...$ should mandatory (  big_smile note to myself ;-) )

I use to do it too, but some times it's not the best...

Stefan wrote:

But i think Rusherman have to sort his files into one with one, two (, or even more) hyphen, because i think there is no single rule to match all occurrences?.

This is why I wasn't trying to match everything.
Just don't know why at the end decided to put $

Because, " - ([^-]+), (\w+)" pretty much does it... or even "([^-]+), (\w+)"


So I would try with this:
1) RegEx: Replace expression "([^-]+), (\w+)" with " $2 $1 " (skip extension)
2) CleanUp: Fix spaces (skip extension)

Last edited by SafetyCar (2011-06-29 15:07)


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

Offline

Board footer

Powered by FluxBB