英文:
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
(?<=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*(?<my_date>\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*(?<my_date>\d{1,2}\/\d{1,2}\/\d{4})
Take a look: https://regex101.com/r/GJxKb7/1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论