如何匹配所有"类型"正确地逃避正则表达式?

时间:2017-06-17 17:09:49

标签: php regex

我目前正在努力匹配以下内容"类型":

(Type): multiplechoice
(Category): 0
(Random answers): 0
(Question): Which of the following is true about pre-test imagery?

(Type): multiplechoice
(Category): 0
(Random answers): 1
(Question): Which of the following is not true about the TMJ?

我在尝试:

preg_match_all("(Type)\:(.+?)\n", $content, $types);

但是我得到了一个未知的修饰符" \"作为错误消息。

如何正确匹配所有类型?谢谢你的任何提示!

1 个答案:

答案 0 :(得分:1)

这应该做,假设后面有空格:

preg_match_all('/\((.+?)\): (.*)?/i', $subject, $array, PREG_PATTERN_ORDER);