Php 从2018年10月22日起,什么样的正则表达式预匹配?

Php 从2018年10月22日起,什么样的正则表达式预匹配?,php,regex,preg-match,preg-match-all,Php,Regex,Preg Match,Preg Match All,自2018年10月22日起,哪些正则表达式preg_与所有正则表达式匹配,不带“-”或“/”,但带“? 我希望preg_匹配所有模式,如2018年10月22日,而不是2018年10月22日,也不是2018年10月22日,检查此regex $date='2018-October-22'; $date2='2018/10/22'; $new_date=preg_replace('/[^a-z0-9]/i', ' ', $date); $new_date2=preg_replace('/[^a-z0-

自2018年10月22日起,哪些正则表达式preg_与所有正则表达式匹配,不带“-”或“/”,但带“?
我希望preg_匹配所有模式,如2018年10月22日,而不是2018年10月22日,也不是2018年10月22日,检查此
regex

$date='2018-October-22';
$date2='2018/10/22';
$new_date=preg_replace('/[^a-z0-9]/i', ' ', $date);
$new_date2=preg_replace('/[^a-z0-9]/i', ' ', $date2);
print_r($new_date);

print_r($new_date2);

你想要的。这应该起作用:

$date1 = DateTime::createFromFormat('!Y F j', '2018 October 22'); // OK
$date2 = DateTime::createFromFormat('!Y F j', '2018-October-22'); // Fail

表示将未解析字段设置为1970/1/1 00:00的相应部分
j
是一个月中没有前导零的一天,
F
是一个完整的月份(因此
Feb
无效),
Y
是一个四位数的年份。

到目前为止您尝试了什么?这个日期是你想要的确切日期还是仅仅是一个例子,所以“2020年6月3日”是可以接受的?是的,只是“2020年6月3日”@KenY NTry基于OPs问题我想你想要的是
'Y F j'
,而不是
'j F Y'
@Nick;我已经确定并使用了OP的日期。