Extracting year regardless of date format

I've been using Format String: $left(%year%,4) to clean up my Year field, but is there a better action that could locate 4 consecutive digits in the YEAR tag (regardless of where they are located within the string) and then use just those 4 consecutive digits as the year (deleting all other characters from the field).

This would allow the year to be extracted regardless of how the date has been formatted.

Thanks.

Action: "Format value"
Field: YEAR_4D
Formatstring: $regexp(%YEAR%,'^.*(\d\d\d\d).*$','$1')

DD.20150118.1540.CET

Thank you so much, DetlevD.

That works perfectly.

too stupid to get that to work....

I do: Actions, Action Group, New (give it a name), Select Action Type Format Value, Field: YEAR, Format String: $regexp(%YEAR%,'^.(\d\d\d\d).$','$1')

It does not work, the YEAR field stays 2017-02-02 after I applied the action.

Everything up to

looks allright to me but you could try as
Format string: $num(%year%,1)
This takes the first number up to the first separator character.

It looks like as the quoted article has been changed when transferring to this new forum.

Several star characters have been lost in the regular expression.
Probably it has been written before like this:

Format string: $regexp(%YEAR%,'^.*(\d\d\d\d).*$','$1')

This forum software is annoying.
So far, I have not discovered any improvement, only worsening.
Sorry to say this.

DD.20180321.1803.CET

Thanks, Detlev. I've fixed the string in the OP.

Danke an beide! Both work now but apperently it is possible to have multiple same-tag attributes in one file. Some of my flacs have 2 Year tags (looks like this in tag panel 2017\2017-11-24) - is there a way to include this occurence in a format string? also, this does show as 2017 in column view, not as both date formats (not that it’s a bad thing but it makes detecting such formatted tags rather difficult).

If you suspect that you have multi-value fields (several fields of the same type) then modify the column definition for "Value", e.g. for YEAR:
Instead of the plain %year% use
$meta_sep(year,\\)

omg it works! dankeschön

In column view that is. Any way I can put that variable (2 values) in the regex so it will kill all but the year number?

I think you can use
$regexp($meta(YEAR),'^.*(\d\d\d\d).*$','$1')
or
$num($meta(YEAR),4)

they both dont change the value in YEAR at all :frowning:

Yes, sorry, this treats only the contents of the first entry.
Use
$num($meta(YEAR),4)\\
which deletes the second field as it enters a null-string for that field.

works fabulously! thanks!