question

danishamir-0686 avatar image
0 Votes"
danishamir-0686 asked ·

regular expression exact date with multiple formats

I have a large file with URL strings such as:

http://tg24.sky.it/mondo/2020/05/01/corea-nord-kim-riappare.html

http://tg24.sky.it/mondo/01/05/2020/corea-nord-kim-riappare.html
http://tg24.sky.it/mondo/2020/04/30/corea-nord-kim-riappare.html

http://tg24.sky.it/mondo/04/30/2020/corea-nord-kim-riappare.html

I need to extract only the URLs with date 01-05-2020 in any format it arrives, with or without separators.

so I have written the following regexp:

^./?0?(1|5|(?:20)?20)[\/-]0?(1|5|(?:20)?20)[\/-]0?(1|5|(?:20)?20)/?.$

it works fine, but also finds false positives such as:

XXXX/5/5/5/YYYYY

So I understand that I need to enhance it in a way - that if the first pattern is MM, then look in the second for DD or YYYY, and then in the third only look for what is left.

An thoughts of how to do it ?

Thanks,

Dani

azure-ad-domain-services
10 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered ·

Hi,

Q&A currently supports the products listed over here https://docs.microsoft.com/en-us/answers/products (more to be added later on).

You might want to reach out to the experts over StackOverflow.

(Please don't forget to accept helpful replies as answer)


10 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.