Author Topic: Regular Expressions Find - Replace Value in Another Field  (Read 1667 times)

Offline NFLineast

  • Newcomer
  • *
  • Posts: 12
    • View Profile
Regular Expressions Find - Replace Value in Another Field
« on: February 19, 2023, 01:39:20 AM »
Hi Team PM,

I did a forum search and a search in the manual to see if I could find something that would point in the direction of my question. Since I did not find anything, I'll ask here.

I am trying to use part of the file names in a larger scope of images to populate the "EVENT" IPTC field. Since the file names are structured it's no problem isolating the desired value.

The filenames are in this format: YYYYMMDD_Event_OriginalFileName_SEQ i.e. 20190306_Motor Race_DSX7744_0001.NEF

So, in the Find/Replace dialogue I have ticked GREP and used the search term

Code: [Select]
([0-9]{8})(_)(.*)(_)
And the replace term

Code: [Select]
$3
No problem so far. PM correctly extracts the Event only and replaces correctly in the file name. So, now that I have the event extracted - how do I use that to populate the Event IPTC field? Does PM have this kind of functionality? It would appear that the standard behavior is to replace in the same field that it finds?

Any help is appreciated. Many thanks!

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25025
    • View Profile
    • Camera Bits, Inc.
Re: Regular Expressions Find - Replace Value in Another Field
« Reply #1 on: February 19, 2023, 01:13:46 PM »
I did a forum search and a search in the manual to see if I could find something that would point in the direction of my question. Since I did not find anything, I'll ask here.

I am trying to use part of the file names in a larger scope of images to populate the "EVENT" IPTC field. Since the file names are structured it's no problem isolating the desired value.

The filenames are in this format: YYYYMMDD_Event_OriginalFileName_SEQ i.e. 20190306_Motor Race_DSX7744_0001.NEF

So, in the Find/Replace dialogue I have ticked GREP and used the search term

Code: [Select]
([0-9]{8})(_)(.*)(_)
And the replace term

Code: [Select]
$3
No problem so far. PM correctly extracts the Event only and replaces correctly in the file name. So, now that I have the event extracted - how do I use that to populate the Event IPTC field? Does PM have this kind of functionality? It would appear that the standard behavior is to replace in the same field that it finds?

No, you cannot find in one field and replace in another.  That said, variable substring extraction could work for this purpose (though it doesn't have the power of regular expressions.)

See: https://docs.camerabits.com/support/solutions/articles/48001077381-variable-substring-extraction

HTH,

-Kirk

Offline NFLineast

  • Newcomer
  • *
  • Posts: 12
    • View Profile
Re: Regular Expressions Find - Replace Value in Another Field
« Reply #2 on: February 19, 2023, 11:00:33 PM »
No, you cannot find in one field and replace in another.  That said, variable substring extraction could work for this purpose (though it doesn't have the power of regular expressions.)

See: https://docs.camerabits.com/support/solutions/articles/48001077381-variable-substring-extraction

HTH,

-Kirk

Many thanks for the explanation. I think for substr() to work, I'd need a nested strpos() function since all event names are of variable length.  But thanks for pointing me in the direction of substring. I'm sure that'll come in handy. Have a great day!

Best,
Joe