config: how to filter only numbers from files name in Image::ExifTool::Composite

Started by richo, February 16, 2021, 09:24:44 AM

Previous topic - Next topic

richo

I have few of my own composite tags in my config file.
I am not very handy with regular expression so I am struggling how to filter only numbers from FileName tag.
I have, for example filename "_DSFC09876.raf" and I would like to get "09876" out of it as a tag name NumberName
-r-

Phil Harvey

There are many ways.  Here is one:

    ValueConv => '$val =~ /(\d+)/; $1',

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

richo

Thank you, this works perfect.
Is there a place I can learn more about the expressions I can use with =~ here ?
-r-

StarGeek

Just search on Regular expressions tutorial and look for one that works for you.  I learned on Regular-Expressions.info.

There are also sites like RegEx101 which allows you to test out regular expressions and give you a break down on how each part works.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

richo

Thanks,
but is the \d+ a regular expression? there are also rathe some types of expression. Does m// s/// also works here?
To me it is all rather confusing.
-r-
-r-

Phil Harvey

The regular expression is /(\d+)/, which is the same as m/(\d+)/ -- you can drop the m if you use / as a delimiter.  Read the links that StarGeek gave if you want to get more into this.

You can use any Perl code in the ValueConv expression, not just regular expressions.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

richo

-r-