匹配特定字符串后的日期格式的正则表达式

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

regular expression to get date format after a particular string match

问题

This is working

(?<=Invoice Value \(in INR\):)\s*\d{1,2}\/\d{1,2}\/\d{4}

But it specifies the spaces and digits after the Invoice Value (in INR):,
but these spaces and digits are not fixed.
And I can't use \s* and \d* inside the quantifier.

英文:

I have to write a regular expression to extract date from this string in python
but date might get repeat so i only want to extract the date after Invoice Value (in INR):
i.e 23/01/2023
the string is

INVOICE DETAILS Invoice Number: Invoice Date: Invoice Value (in INR): 19 23/01/2023 2416.5 ITEM DETAILS CTSH:42029900 (ii) SKU NO : (iii)

This is working
(?&lt;=Invoice Value \(in INR\):\s\d\d\s)+\d{1,2}\/\d{1,2}\/\d{4}

But it specifies the spaces and digits after the Invoice Value (in INR):
but these spaces and digits are not fixed
And I can't use \s* and \d* inside the quantifier

答案1

得分: 1

使用一个捕获组(命名为 my_date)可能有更好的方法,但这个方法可以工作:

Invoice Value \(in INR\):\s*\d*\s*(?&lt;my_date&gt;\d{1,2}\/\d{1,2}\/\d{4})

请查看:https://regex101.com/r/GJxKb7/1

英文:

Surely there's something better, but this would work, using a capture group (named my_date):

Invoice Value \(in INR\):\s*\d*\s*(?&lt;my_date&gt;\d{1,2}\/\d{1,2}\/\d{4})

Take a look: https://regex101.com/r/GJxKb7/1

huangapple
  • 本文由 发表于 2023年2月24日 03:48:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549654.html
匿名

发表评论

匿名网友

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

确定