英文:
Date regex, exclude issue
问题
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
What I have tried:
(?:日期 : )?(?:(?:[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)
Its still capturing Loss Date : MM/DD/YYYY part in bold. I want the regex to totally exclude Loss Date Data.
英文:
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
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)
Its still capturing Loss Date : MM/DD/YYYY part in bold. I want the regex to totall exclude Loss Date Data.
答案1
得分: 1
谢谢大家,这两个正则表达式都有效。我在这里看不到接受按钮来解决这个帖子。
((?<=不是Loss的 )日期:)\d\d/\d\d/\d{4})
不是Loss的 日期:(?:02/.-|(?:0[469]|11)/.-|(?:0[13578]|1[02])/.-)[/.-][0-9]{4}
英文:
Thank you everyone, These both regex are working. I dont see accept button to resolve this post here.
((?<=(?<!Loss )Date : )\d\d/\d\d/\d{4})
(?<!Loss )Date : (?:02/.-|(?:0[469]|11)/.-|(?:0[13578]|1[02])/.-)[/.-][0-9]{4}
答案2
得分: 0
这将匹配任何在 "Date : "之前,而且不在 "Loss "之前的 \d。
英文:
A simple approach would be the following.
((?<=(?<!Loss )Date : )\d\d/\d\d/\d{4})
This will match any \d which is preceded by "Date : ", which subsequently is not preceded by "Loss ".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论