REGEX to find YEAR in given string

I want to format the year (YYYY) from a string.

$regexp(abc123197588trs,'^.*((19|20)(\d\d)).*$',$1) returns 1975 as expected.

$regexp(ab0244,'^.*((19|20)(\d\d)).*$',$1) returns ab0244.

What's wrong?

Does not match as you have "02" instead of "20".

If there is no match I expect to get no string back. :thinking:

no, if there is no match then the original string is returned

Oops!

How to find a valid year (YYYY) in a string with no specific structure/content?

I don't understand.
Finding a valid year would then depend on the regular expression to return nothing if the pattern does not produce a hit?
I find it actually as some kind of safety measure: if you have a non-matching expression, you don't loose data. So you could apply another expression to yield better results.

If you have no structure in a string ... then I don't think that anyone would find anything like a "year" (and a spcificly a valid one) in that string.
Could you explain a little more, please?

I try to fill the tag YEAR.
When performing an automated action and the field YEAR is empty I would like to scan _dirname or _filename for a valid value.
Doing so I don't know if $REGEX will find something useful and leave the YEAR untouched when no match is given.

I am always a friend of filters. With those you can leave out all the files that may lead to surprises - and I think that filling the year like that will happen once in the lifetime of a file. So it does not have to be the omnipotent action that takes into account all possibilities.

A filter like
%_path% MATCHES \d\d\d\d AND %year% MISSING
Should display all the candidates.

Thank you ohrenkino for your suggestĂ­on.
It solves this issue in a specific situation.
But in my case it is only one of 20 (or more) automated steps.

So the solution that I need is, to know if there is a number within a range from 1900 to 2099 in a string.
If so I can use $REGEX alone.
Otherwise I have to check the returned value again if it fits in the given boundaries.
($num(string,4)) + $ifgreater(a,b,x,y) + ..
If the found number is not in the given range YEAR must be reseted.
Seems too complicated, is there no easy way to do this?

you could test for the returned string with $num() - if that is 0 (which means there are leading non-numeric characters) then you could do more processing.

Still, I wonder why it has to be so complicated? Why devise 20 steps (or more) in 1 go - with a lot of thinking and trial and error going into it - instead of simple, dedicated actions that perform just one task. And I can define the einvironment and see which is the action to take.
But here, everybody is the smith of his own workflow...