Note however It will match a string with mixed delimiters like this 2/12-73 that may not actually be a valid date. You can optimise this part of the pattern to speed up matching, but this is a good foundation that detects most valid delimiters. The colon has to be there to prevent matching on times that look like dates (see my test Data) This will match anything that is not a word character, digit character, carriage return, new line or colon. In my exploration of the issues, I have come up with a system that enables you to build a regular expression by arranging together four simpler sub-expressions that match on the delimiter, and valid ranges for the year, month and day fields in the order you require. But I then discovered, as many of the answers and comments have comprehensively highlighted, there are many pitfalls that make constructing an effective pattern very tricky when extracting dates that are mixed-in with poor quality or non-structured source data. I landed here because the title of this question is broad and I was looking for a regex that I could use to match on a specific date format (like the OP).
0 Comments
Leave a Reply. |