4

In the firm I work for, they have file naming system. It always has 5 sections as in the examples below:

File Name: YYMMDD_PROJECT NUMBER_PROJECT NAME_FILE NAME_initials.ext

140527_207_AL MURR VILLA_INFO_ne.doc 140527_207_AL MURR VILLA_MAIN ENTRANCE_ne.jpg 140527_207_AL MURR VILLA_PROPOSED SECTION EAST VIEW_ne.jpg

In my indesign, I am working with hundreds of projects images. Instead of writing the titles of the image, I want to grab this from the file name itself. I use Insert Variables/ Image name. It works but it grabs all the file name including the extension as well. What I want to do is to get only the fourth section from the file name above. It always comes after the third underscore and before the fourth one.

I'm not sure if it's doable or not, since it has multiple underscores in it. I thought I better ask the experts.

Thanks in advance.

  • Were you thinking of using a grep style to hide the prefix and suffix? Can you apply a grep style to a text variable? (I tried and couldn't.) – MG_ Aug 19 '14 at 13:52
3

Regular expressions is a general programming concept and by no means only something found in InDesign (in pretty much fact every programming language out there has regexp support). So you can ask these questions on stack overflow you get a much faster answer.

Now the grep of grep styles is different from the grep of search and replace (match versus replace in general programming). So if you search you have something called capture groups that are inside parentheses, you can then fill them in later in the replace with $ capture group number. you can then search and replace with:

  • Find What as, (.*)_(.*)_(.*)_(.*)_(.*).(doc|jpg)
  • Change To as: $4
  • Replace as much as you need.

So running this on your test:

140527_207_AL MURR VILLA_INFO_ne.doc
140527_207_AL MURR VILLA_MAIN ENTRANCE_ne.jpg
140527_207_AL MURR VILLA_PROPOSED SECTION EAST VIEW_ne.jpg 

Becomes:

INFO
MAIN ENTRANCE
PROPOSED SECTION EAST VIEW 
| improve this answer | |
  • I guess it should be noted that it won't work unless all text variables are converted to regular text, before doing the find-replace. – MG_ Aug 19 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.