Home Ask Login Register

Developers Planet

Your answer is one click away!

Craig February 2016

c# exclude regex pattern

I am parsing several text files looking for date fields. I want to find this pattern - Date: mm/dd/yyyy but want to exlude this pattern - Cheque Date: mm/dd/yyyy. I have this working for finding the first pattern but it also finds the second pattern as well -

string pattern = @"Date:\s*(.+?)\r";

Using this pattern I can find all combination of dates and not just mm/dd/yyyy.


Jan February 2016

In addition to my comment, you may want to use an anchor:

string pattern = @"^Date:\s*(.+?)\r";

Post Status

Asked in February 2016
Viewed 2,979 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life