Regex with Exiftool – Removing characters from a group question

Started by philbond87, August 27, 2020, 08:12:40 PM

Previous topic - Next topic

philbond87

The forum recently helped me with this but I have to refine it.

The Exiftool command contains a regex that forms a string from three regex groups.
At the end of the command I remove certain characters from the string BUT what I really need to do is remove those characters only from the third group.

Here is my command, as it's currently implemented:
exiftool -overwrite_original_in_place -r '-transmissionreference<${filename;m/(\d{6}).*_([A-Z]{2,})_?([iwOSEV]*\d{6})/;$_=$1.$2.$3;s/w//;s/E//;s/O//;s/S//}'

I had thought that I was removing "w", "E", "O", "S" from the third group but I was actually removing them from the entire string.
How can I remove them from the third group only?

Thanks!

philbond87

I suppose this is more of a pearl question then.

I have tried this, which seems to work for getting one of the needed characters removed in the last group, but I can't figure out the syntax to get more than one character removed:
exiftool -overwrite_original_in_place -r '-transmissionreference<${filename;m/(\d{6}).*_([A-Z]{2,})_?([iwOSEV]*\d{6})/;$_=$1.$2.($3=~ s/w//r)}'

philbond87

I think I've found the solution.
I think I can simply stack the replacement characters in the single substitution expression with logical ors.

;$_=$1.$2.($3=~ s/w|E|O//r)}'

StarGeek

Glad you found a solution.  I didn't go through your regex but one thing to take note about your final post is that only the first of those letters will get removed.  For example, given WoOeEw, only the O will get removed.  To remove all matching characters, add g so the substitution will be global.  Also the first letter will not get removed because it is a capital W and the case insensitive modifier (i) isn't there.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

philbond87

Thanks.

There will only be one of each of the selected characters in the third regex group (which is the only group I'm concerned with removing those characters from).
If I did want to account for multiple occurrences in the third group where would I put the 'g' global to the substitution expression?

Also I am only concerned with removing a possible, single lowercase 'w' so that should be fine.

Thanks again.

philbond87

@StarGeek,

I spoke a bit too soon. I misunderstood what you were saying about the global modifier.
Yes, I do need the global modifier to get all of the occurrences of the characters.

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype