ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: jmiller on January 12, 2023, 03:09:40 PM

Title: Extract String Between Two Underscores - Regex Help
Post by: jmiller on January 12, 2023, 03:09:40 PM
Hi Everyone,

I previously had an EXIF Regex Parser I had created to extract a string between two underscores in a filename and write it into the Model XMP attribute. After picking up my project after a couple of weeks, suddenly its not working. Can someone point me to how to adjust the REGEX to get this working?

Example:
10010088_1_.jpg

Command:
exiftool "-Model<${Filename;s/_([^_]+)_"

Result:
10010088_1_.jpg;s_([^_]+)_

Desired Result:
1
Title: Re: Extract String Between Two Underscores - Regex Help
Post by: Phil Harvey on January 12, 2023, 05:21:09 PM
Your command has a few problems.  Try this:

exiftool "-xmp:Model<${Filename;$_ = /_([^_]+)_/ ? $1 : undef}" FILE

- Phil