ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: infotalk on October 28, 2012, 09:52:17 AM

Title: Delete comma
Post by: infotalk on October 28, 2012, 09:52:17 AM
I have one JPG that contains keywords like this example:

german1, german2, |, english1, english2

After

        MyLanguageVerticalbarGermanIPTCKeywords => {
            Require => 'IPTC:Keywords',
            ValueConv => q{
                $val = [ $val ] unless ref $val eq 'ARRAY';
                my @newKeywords;
                foreach (@$val) {
                     /^(.*?),? ?\|,? ?(.*?)$/ and push(@newKeywords,$1), last;
                     push(@newKeywords,$_);
                }
                return @newKeywords ? \@newKeywords : undef;
            },
        },
        MyLanguageVerticalbarEnglishIPTCKeywords => {
            Require => 'IPTC:Keywords',
            ValueConv => q{
                $val = [ $val ] unless ref $val eq 'ARRAY';
                my @newKeywords;
                foreach (@$val) {
                     /^(.*?),? ?\|,? ?(.*?)$/ and push(@newKeywords,$2), next;
                     push(@newKeywords,$_) if @newKeywords;
                }
                return @newKeywords ? \@newKeywords : undef;
            },
        },

I get two JPGs and the keyword part looks like this:
german1, german2,
, english1, english2

How can I delete the last comma after german2?
How can I delete the comma and the blank space before english1?

I have read:
\A
    Matches only at the start of the string.
\Z
    Matches only at the end of the string.

How can I realize this with ExifTool?

Thank you!
Title: Re: Delete comma
Post by: Phil Harvey on October 28, 2012, 01:38:16 PM
Which commas are keyword separators and which are part of the keywords themselves?:

german1, german2, |, english1, english2

- Phil
Title: Re: Delete comma
Post by: infotalk on October 28, 2012, 01:58:20 PM
Thank you Phil for your reply!

, |,

comma...blank space...vertical bar...comma...blank space
Title: Re: Delete comma
Post by: Phil Harvey on October 28, 2012, 06:46:28 PM
Sorry, you lost me.

For example, I was looking for an answer something like this:

    There are 3 keywords in my example:

    1) "german1, german2"

    2) "|"

    3) "english1, english2"

- Phil
Title: Re: Delete comma
Post by: infotalk on October 29, 2012, 03:18:09 AM
Hope this helps:

1) "german1, german2"

2) ", |, "
comma...blank space...vertical bar...comma...blank space

3) "english1, english2"
Title: Re: Delete comma
Post by: Phil Harvey on October 29, 2012, 07:13:47 AM
Great, thanks.

Try this:

        MyLanguageVerticalbarGermanIPTCKeywords => {
            Require => 'IPTC:Keywords',
            ValueConv => q{
                $val = [ $val ] unless ref $val eq 'ARRAY';
                my @newKeywords;
                foreach (@$val) {
                     /^(.*?),? ?\|,? ?(.*?)$/ and last;
                     push(@newKeywords,$_);
                }
                return @newKeywords ? \@newKeywords : undef;
            },
        },
        MyLanguageVerticalbarEnglishIPTCKeywords => {
            Require => 'IPTC:Keywords',
            ValueConv => q{
                $val = [ $val ] unless ref $val eq 'ARRAY';
                my (@newKeywords, $found);
                foreach (@$val) {
                     /^(.*?),? ?\|,? ?(.*?)$/ and $found = 1, next;
                     push(@newKeywords,$_) if $found;
                }
                return @newKeywords ? \@newKeywords : undef;
            },
        },


- Phil
Title: Re: Delete comma
Post by: infotalk on November 05, 2012, 06:59:02 AM
That's it! Thank you very much Phil.