add the word DVD to files

A swapping-ground for Regular Expression syntax

add the word DVD to files

Postby username99 » Sat Oct 08, 2011 6:13 pm

I am trying to add the word 'DVD' to many files. However, it can't always be attached as a suffix, because there are files called .fanart.jpg. The 'DVD' needs to go before .fanart for these files, and before .*** on the other files.

Here is an example:

**Original**
Animal House.avi
Animal House.fanart.jpg
Animal House.jpg
Animal House.nfo

**Change To**
Animal House DVD.avi
Animal House DVD.fanart.jpg
Animal House DVD.jpg
Animal House DVD.nfo
username99
 
Posts: 1
Joined: Sat Oct 08, 2011 6:05 pm

Re: add the word DVD to files

Postby Jane » Sun Oct 09, 2011 7:27 pm

Try this
Regex(1)
Match: ([^.]+)(.*)
Replace: \1 DVD\2

Include Ext. box NOT CHECKED.

[^.] means any character except a dot

([^.]+) captures the original filename up to the first dot, (.*) captures the rest.
Multiple dots in the filename won't affect it because it stops looking for the dot when it hits the first one.
\1 DVD\2 adds a space and DVD to this filename, and the extension is not changed from the original

HTH,
Jane
Jane
 
Posts: 24
Joined: Sat Aug 05, 2006 1:20 am

add an string before first dot

Postby Stefan » Wed Oct 12, 2011 7:08 am

[^.] means any character except a dot

Wow, good solution.
And it works for me.


I wanted to solve this too, but had no glue how at first look :roll:

Thanks Jane.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions