regular expression to get date format after a particular string match
Question:
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):sdds)+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
Answers:
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
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):sdds)+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
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