Skip to main content
Nintex Community Menu Bar
Answer

Extracting 4 digit year out of date using Regular Expression?

  • April 23, 2019
  • 3 replies
  • 377 views

Forum|alt.badge.img+6

Regular Expression is bewildering.  I know dozens of programming languages at a basic-intermediate level and this one throws me for a loop!  Yes I have seen all the documentation and did Google searches but I just don't get the logic. 

 

I have a workflow that I did not build and this Regular Expression pattern is not coming through like it is on the original list (rebuilding it).  Looks like the date format is even completely diffierent than the new one. 

 

All I need is the year from the date... In this case, 2019.

Variable holding the date contains: 4/23/2019 3:42:11 PM

 

Best answer by nico

Hi,

you can use this regex:

(d{4})

It say : I want the 4 consecutive digit, and in a date, there is no other 4 digit consecutive thant the year

3 replies

nico
Forum|alt.badge.img+10
  • Rookie
  • Answer
  • April 24, 2019

Hi,

you can use this regex:

(d{4})

It say : I want the 4 consecutive digit, and in a date, there is no other 4 digit consecutive thant the year


Forum|alt.badge.img+6
  • Author
  • April 24, 2019
It took out the year but left me with everything else... This was my output: 4/24/ 8:29:48 AM

Forum|alt.badge.img+17
  • April 24, 2019

Here is a video walking through how to apply the regex that @nico provided. It does work and you can import the workflow if needed.