InDesign identify and replace text

Guys, I need you help with InDesign.

I am designing a catalogue with thousands of photos. Under every photo I should type the code of the product/photo. The photos have that exact syntax in their name “1010-1201 INKY BLUE304 1.jpg”. Another example is “1101-0977 ROSEWOOD407 2.jpg” I am interesting for the 8 digits with the hyphen only, which they are always in the beginning of the filename. Under the photo I input a text field in InDesign CC where I should type these 8 digits with the hyphen (1101-0977). I don’t know how to bind this text field with the photo and input the first 8 digits and the hyphen automatically.

So my thought is… How this text field can recognize the first part of the filename (1101-3456) which is unique on every photo and type it in this field?

Any idea?

Browser: Safari 537.36
Operating System: Mac OS X (10.10)

Hi,

try this; this script walks thru every group on each page, so make shure only your illustration and textframe which belong together are grouped and nothing else.

Kind regards, Eric