我想从以下格式的字符串中匹配并提取主题和人物: ((当| Where)是)? (我的|的)? (下一个)? (学科)? (会议|事件)? (与(人))?
可能的句子:
我与David Sharma(Person = David Sharma)的会面是什么时候? 午餐(主题=午餐)会议在哪里? 星期五午餐是什么时候(主题=星期五午餐)? 我与约翰(人)的下一次晚餐(主题)活动在哪里?
以下是我在各种尝试后的结果,但有些查询或其他查询不匹配:
if (preg_match("/(?:(?:when|where)\s+is\s+)?(?:(?:my|the|your)\s+)?(?:next\s+)?((\S+\s+|\S+\s+\S+)+)?(?:(?:event|meeting)\s+)?(?:with\s+(.*))?/", $query, $matches)) {
print_r($matches[1]); //subject
print_r($matches[2]); //person
}
试试Regex:^(?:when|where) is(?: (?:my|the|your))?(?: next)?(?: (?:((?!event|meeting)[\w ]+?)))?(?: (?:event|meeting))?(?: with ([\w ]+))?\?$