I have a preg_match to get dates from a string:
preg_match_all('/\d{1,2}\.\d{1,2}\.\d{2,4}/',$myString,$dates);
This will get dates with the syntax:
01.01.2022
1.01.2022
1.1.2022
1.1.22
...
Now I have a date format like this:
25 März 2023
or
25 March 2023
How can I get this?
You could write the pattern as:
Explanation
\bA word boundary\d{1,2}Match 1-2 digits(?:Non capture group\.\d{1,2}\.Match.1-2 digits.|Or\h+\p{Lu}\p{Ll}+\h+Match any uppercase char followed by 1+ lowercase chars between 1+ horizontal whitespace chars)Close the non capture group(?:\d\d|\d{4})Match 2 or 4 digits\bA word boundarySee a regex demo and a PHP demo.
Output