Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am new to regex and still learning. I am writing a regex to capture date from multiple pdf files. On the pdf files there are 2 dates mentioned in below format. I just want to capture First one and exclude Loss Date from my results. The regex I use is still capturing Loss Date. Can you please help me and let me know how can I exclude Loss Date?

Thank you

https://i.ibb.co/XZD0kSz/image.png[^]

What I have tried:

(?:Date : )?(?:(?:[12][0-9]|0[1-9])[/.-]02|(?:30|[12][0-9]|0[1-9])[/.-](?:0[469]|11)|(?:3[01]|[12][0-9]|0[1-9])[/.-](?:0[13578]|1[02]))[/.-][0-9]{4}


To exclude I tried
(?!\s*Loss Date)
Posted
Updated 13-Jun-23 3:07am

I'd use regex pattern like that:
^(?:(?<!Loss )Date : )(?<Month>(0[1-9]|1[0-2]))\/(?<Day>(0[1-9]|1\d|2\d|3[01]))\/(?<Year>((19|20)\d{2}))$


Demo: regex101: build, test, and debug regex[^]

BTW: i suggest to read this: Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions[^]
 
Share this answer
 
Thank you for your help. I tried it but it didnt work. I was able to found a solution using below regex.

(?<!Loss )Date : (?:02[/.-](?:[12][0-9]|0[1-9])|(?:0[469]|11)[/.-](?:30|[12][0-9]|0[1-9])|(?:0[13578]|1[02])[/.-](?:3[01]|[12][0-9]|0[1-9]))[/.-][0-9]{4}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900