Delete comma

Started by infotalk, October 28, 2012, 09:52:17 AM

Previous topic - Next topic

infotalk

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!

Phil Harvey

Which commas are keyword separators and which are part of the keywords themselves?:

german1, german2, |, english1, english2

- 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 ($).

infotalk

Thank you Phil for your reply!

, |,

comma...blank space...vertical bar...comma...blank space

Phil Harvey

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
...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 ($).

infotalk

Hope this helps:

1) "german1, german2"

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

3) "english1, english2"

Phil Harvey

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
...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 ($).

infotalk

That's it! Thank you very much Phil.