Get part of a String and text before it


I need to retrieve the date from a string. the output string is from a pdf and im verifying the date. the date is going to be different for each pdf. So I need to grab from the bottom “18 January 2019”

"CERTIFICATE of COMPLETION\r\nThis is to certify that\r\nname\r\nhas completed the course\r\nChild Protection Awareness Training\r\n18 January 2019\r\nPowered by TCPDF ("

There will also be different structures of the pdf where it doesnt grabbed all of the text and just name and date for e.g.

First Name Last Name\r\n2 September 2019\r\nPowered by TCPDF ("

So I need some help getting to the YEAR and then taking the whole date and cutting out anything else before that



will you get always Powered by TCPDF ( after the date ?


I believe so.

Hi @michael.p.wilson
Use this link for your reference.

cheers :smiley:

Happy learning :smiley:

1 Like

Hi @michael.p.wilson,

You can use the regex, \d\d? \w+ \d{4} to capture the date values. Please have a look at this.

Please assign String_var =System.Text.RegularExpressions.Regex.Match(Your_String,"\d\d? \w+ \d{4}").ToString

Warm Regards,
Nimin :slightly_smiling_face:


Perfect. Thank you

1 Like

I need to comment my code. Is it possible to explain what the expression is doing?

\d is matching a single digit, ? means the character is optional, \w matches a word and \d{4} matches exactly 4 digits.
Check out a site like regexr to have a play around with what it’s doing. They have a cheatsheet on the left with the different symbols so you don’t have to know what they are straight away.
Here’s one with your sample:
Check out the Explain tab down the bottom to see which part of the pattern is matching each part of your string.


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