Mobile app version of vmapp.org
Login or Join
Hamm6457569

: How can I use GREP to get all text between the third and fourth underscore in a file name? In the firm I work for, they have file naming system. It always has 5 sections as in the examples

@Hamm6457569

Posted in: #Grep #IndesignScripting

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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamm6457569

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kimberly620

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:
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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme