Help to Regular expression :)

#1

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

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

Someone who can help ??

0 Likes

#2

How about
^[0-9]{4}\K.*

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.

0 Likes

#3

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%

0 Likes

#4

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.

0 Likes

#5

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

#6

True, that is a good one.

0 Likes

#7

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

0 Likes

#8

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:
$left(%year%,4)

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

0 Likes