1

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.

4
  • 1
    Use an anchor: @"^Date:\s*(.+?)\r"; binds it to the beginning of the string. Commented Feb 8, 2016 at 19:05
  • try a negative look behind. Commented Feb 8, 2016 at 19:06
  • Is the entire line "Date: mm/dd/yyyy" or "Cheque Date: mm/dd/yyyy", or could there be other characters before those patterns? Commented Feb 8, 2016 at 19:09
  • Try this: regex101.com/r/mA5rE4/1 Commented Feb 8, 2016 at 19:10

1 Answer 1

1

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

string pattern = @"^Date:\s*(.+?)\r";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.