我猜的是一个相当基本的正则表达式问题:
// Example strings
$string = "test test 24/11/2009";
$string = "test test 21-11-09";
$string = "test testtest 24.11.2009test";
$delim = "(\.|-|/)";
// dd/mm/yyyy
preg_match("#[^0-9](\d{1,2})$delim(\d{1,2})$delim(20\d{2})[^0-9]#i", $string, $result);
// dd/mm/yy
preg_match("#[^0-9](\d{1,2})$delim(\d{1,2})$delim(\d{2})[^0-9]#i", $string, $result);
现在我想匹配分隔符而不将它们显示在$ result数组中。
答案 0 :(得分:4)
分隔符是“。”,“ - ”,“/”中的一个:并且它们不包含在$ result中,因为它们不在“()”中
$delim = "[./-]+";
答案 1 :(得分:1)
非捕获组应该完成这项工作:
$delim = "(?:\.|-|/)";