Help to Regular expression :)

Hello I want help removing the date in the year field (Regular expression):

2010\2010-03-01 -------->2010

Someone who can help ??

How about

Here we match the first four digits with ^[0-9]{4}
Then we use \K to keep the text matched so far out of the overall regex match.
And lastly we use .* to match the rest of the string witch is the part that will be removed.

You would use Actions > Actions (Quick) > Replace with regular expression

Field: YEAR
Regular expression: ^[0-9]{4}\K.*
Replace matches with stays empty.

If the regular expression is not mandatory, I am a real fan of the action "Guess value" (import tag fields)
Source: %year%
Target: %year%\%dummy%

Yes, that will work too, but Guessing pattern must then be adjusted depending on what is in the Year field. For example, if the Year field contains 2010-03-01, then the Guessing pattern must be %year%-%dummy%, and if the field contains 2010.03.01 it must be %year%.%dummy%. If the field actually contains 2010\2010-03-01, then %year%\%dummy% would work.

You are right.
What about an action of the type "Format value" for YEAR
Format string: $num(%year%,1)
This should always take that what stands in front of the first non-numeric character.

1 Like

True, that is a good one.

Thanks for the answer can you explain to me how this command works?

To use this command, you select Actions > Actions (Quick) > Choose Format value > OK

Field: YEAR
Format string: $num(%year%,4)

The $num fuction returns the year number with 4 digits, padding with leading zero(s), in this case if the number is below 4 digits.

Another function that could be used is left:

This is a string function and returns the leftmost characters of a string, in this case first 4 characters.