stuck in a rut seperating digit from character file name

A swapping-ground for Regular Expression syntax

stuck in a rut seperating digit from character file name

Postby asdf » Wed Feb 02, 2011 8:34 am

Hi,
Cant quite find the solution for my problem - i am stuck with a huge directory of images and need the structure to match.
There are 2 problems - first is the string at the end of file name -the colors - change from 3 character like red to longer colors like Navy or ltblue
Second, the middle string (after the first 3 number and . ) is usually 3 digit characters but sometimes it is a letter followed by 2 digits

Here is some examples of what i got
106.755black.jpg or
104.s56ltblue.jpg or
258.866peri.jpg or
109.049khaki.jpg

I need it to be
102c.755.black.jpg or
104.s56.ltblue.jpg or
258.866.peri.jpg or
109.049.khaki.jpg

Any ideas?
thanks
asdf
 
Posts: 1
Joined: Wed Feb 02, 2011 8:17 am

Re: stuck in a rut seperating digit from character file name

Postby Stefan » Sat Feb 12, 2011 7:00 pm

asdf wrote:Hi,
Cant quite find the solution for my problem - i am stuck with a huge directory of images and need the structure to match.
There are 2 problems - first is the string at the end of file name -the colors - change from 3 character like red to longer colors like Navy or ltblue
Second, the middle string (after the first 3 number and . ) is usually 3 digit characters but sometimes it is a letter followed by 2 digits

Here is some examples of what i got
106.755black.jpg or
104.s56ltblue.jpg or
258.866peri.jpg or
109.049khaki.jpg

I need it to be
102c.755.black.jpg or
104.s56.ltblue.jpg or
258.866.peri.jpg or
109.049.khaki.jpg

Any ideas?
thanks



As far as i see you want just an dot after the last digit?


FROM:
106.755black.jpg
104.s56ltblue.jpg
258.866peri.jpg
109.049khaki.jpg

TO:
102c.755.black.jpg
104.s56.ltblue.jpg
258.866.peri.jpg
109.049.khaki.jpg

DO:
RegEx(1)
Match: (.+\d)(.+)
Repla: \1.\2

Explanation:
(.+\d) => match all signs greedy till last digit
(.+) => match the rest

\1 => replace with was is matched in first ()-group
.   => insert an dot
\2 => replace with was is matched in second ()-group



HTH? :D
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions