日期正则表达式,排除问题

huangapple go评论72阅读模式
英文:

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.

((?&lt;=(?&lt;!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 ".

huangapple
  • 本文由 发表于 2023年6月9日 10:04:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定