I want to compare the year from the word document and the year from our computer.
I have already get the year from the computer using System.DateTime.Now.ToString(“yyyy”)
The problem now is how do I get the year from the string, shown in the picture above?
The string has 2 number, 2017 and 2.
How do I know which number is the year?
This is a look ahead regular expression. For the string, “Feb 2017 Time allowed: 2 hrs” only “\d{4}” is enough to capture the year. But if there is a possibility of more than one year in your string, for eg: “Feb 2017 Time allowed: 2 hrs. Now it’s 2019” , (?=\sTime) will looks for presence of 4 digits(\d{4}) before the word “Time”. That’s it.