I want assign to the %year% tag the first value found in %_directory% that starts with 19 or 20 and include the following two digits (to form the year). I have been trying to use the Format Value action.
$regexp(x,expr,repl)
replaces the pattern specified by the regular expression expr in the string x by repl. The
fourth optional parameter enables ignore case (1) or disables the ignore case setting (0).
Please note that you have to escape comma and other special characters in expr
My directories have names like:
1991 - Eric Clapton - 24 Nights
The Turtles - 20 Greatest Hits (1984)
1985 - George Benson - 20-20
Field=YEAR
Format string=$regexp(%_directory%,'(\b\d{4}\b)','$1') returns %_directory% (no change)
Format string=$regexp(%_directory%,'(\d{4})','$1') returns %_directory% (no change)
Format string=$regexp(%_directory%,'(19|20)\d{2}','$1') returns the original %_directory% string with the 2 chars after 19 or 20 stripped.
Format string=$regexp(%_directory%,'\b(19|20)\d{2}\b','$1') returns the original %_directory% string with the 2 chars after 19 or 20 stripped.
Format string=$regexp(%_directory%,\b\d{4}\b,'$1') returns everything but the year that I want! The year is stripped. I want exactly the opposite of this, I want the year as the result. This is a very simple regex and I don't know why it returns the opposite of what I want. If I remove the \b's the result is the same.
Result (opposite of what I want!):
- Eric Clapton - 24 Nights
The Turtles - 20 Greatest Hits () (FLAC+CUE) - George Benson - 20-20
I'm not sure how to do the parenthesis grouping and using the $1 stuff, may be the trick.
The below example should be perfect, but my results are the opposite of expected.
It has: 1. the stuff I want to ignore (not in parenthesis), 2. the stuff I want (in parenthesis), and 3. the stuff I don't want at the end (not in parenthesis).
I checked similar posts and one user had success with the regular expression: $regexp(%YEAR%,'^.(\d\d\d\d).$','$1')
I tried this and it gave me everything but the year (year had been stripped) and got result.
Try my examples. Do you get the same result? Can anyone figure this out?
It is very useful to grab years from the directory name.
Is is broken? This should be simple.
Please help!