In the previous question, this is the link:
I got help from a colleague and solved the problem of automatic fill of attributes and the code
clamp( 1, length(regexp_replace(Naziv,'[^-]',''))+1, 3 )
does the job perfectly if I use it in the field calculator. When I entered the code in the form attributes and set it to be the default value -> Preview shows '1' but fills the attribute table with the value 'NULL'. And to make it even more interesting, if I record a line with Mergin Maps in that project and synchronize the data, the table is correctly filled with the value it should be.