Help for extracting single date from 2 dates appearing in the text using REGEX

Hello,

Looking for REGEX help to extract 1 date from 2 dates appearing next to each other in the text. Form the text below :-

(if any): Phone: XXX-XXX-XXXX
Term Start Date: Initial Term End Date: March 1,2021 February 29,2024 other#: Affiliated #s: 99991

Note: This offer, as generated on January 27, 2021 is valid for 60 days.
I have given the following regex :-
(?<=Term End Date:)([\S\s\t]?)([a-zA-Z]+[\s][\d]{1,2},[\s]?[\d]{4})
(?:[\s] (?=\s))

However, it extracts both the dates as show in the image below

I want to extract only the first one
March 1, 2021

Any help is appreciated
Regards
AV

@Aditi.av

This will extract both values
You can assign that to a Ienumerable variable and you can extract by that index
Variable(0) will access the first value

Hope this may help you

Thanks

Could you please try this…

(?<=Term End Date:\s+)\w+\s+[\d,]+

Hello @prasath17

Thanks, this works when there is no space after,
Term Start Date: Initial Term End Date: March 1,2021 February 29,2024
However, in my original doc most of the time there is a space after ,

Term Start Date: Initial Term End Date: March 1, 2021 February 29, 2024
In that case (?<=Term End Date:\s+)\w+\s+[\d, ]+ works in the regex tester you use, but when I enter it in the regex editor in UIPATH it doesn’t work and extracts only until March 1, 2

What could be the reason for that?
Regards
AV

@Aditi.av - Could you please try this…

image

Since it is capturing a additional space after that…just use Regexvar(0).value.trim or Regexvar(0).tostring.trim

Thanks a ton. This worked. I was trying to work this out for couple of days and as you can see was using a very long expression too :slight_smile:

1 Like

@Aditi.av - Since we have already added \s in the character set…we can remove that after \w+ please check the updated pattern below…

Yes this works.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.