RegEx Error: Unmatched ( in regex

Started by ejm554, September 10, 2018, 03:24:39 PM

Previous topic - Next topic

ejm554

I'm trying to see what a JPEG's BaseName tag would look like when modified with a regular expression. I'm having trouble with the syntax.

For sake of example, the base name of my file is 20180101T000000.IMG_0205.0.0.
I want to strip off the leading timestamp and the dot-zero-dot-zero at the end, i.e., IMG_0205.

Here's my command line entry:
$ exiftool -g1 '-$[Basename;s/[0-9T\.]{16}(.*)(?=.0.0)/$2/}' 20180101T000000.IMG_0205.0.0

The following error is returned:
Unmatched ( in regex; marked by <-- HERE in m/^$[basename;s/[0-9t\.]{16}(.[-\w]*)( <-- HERE [-\w]$/ at /usr/local/bin/lib/Image/ExifTool/TagLookup.pm line 9978.

So I think the error is telling me that I'm missing a closing paren, but I'm not sure why it thinks so. I experimented with escaping various characters, but it didn't help.

Please advise.
EJ

StarGeek

Follow the dollar sign with a opening brace {, not a bracket [.

A couple of notes, (?=.0.0) is a positive lookahead.  It won't get stripped.  The dots in that section are not being escaped.  Probably not a problem but it would also match A0B0, for example.

You only have one capture group, so $2 won't return anything.  You want $1.
"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

ejm554

Oh, thanks. I see the mismatched symbols now. However, replacing the bracket with a brace didn't change the result, i.e., I get the same error message. Do you see any other typos?

Btw, I haven't reviewed  the lookahead or capture group issues yet, but thanks for the heads up.

EJ

StarGeek

#3
D'oh!  I was looking so carefully at the regex, I didn't notice that you were trying to use advanced formatting on a tag listing.  Advanced formatting feature can be used with "any tag interpolated within a -if or -p option argument, or a -tagsFromFile redirection string".  It can't be used directly on a tag like that.

You either have to use the -api Filter option, which will affect all tags extracted, or use the -p option to list tags.

exiftool -g1 -p '${Basename;s/[0-9T\.]{16}(.*)(?=.0.0)/$1/}'
or
exiftool -g1 -Basename -api 'Filter=s/[0-9T\.]{16}(.*)(?=.0.0)/$1/}'

Edit:  Oops, forgot important part of the first command.  Fixed.
"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