0

I am currently struggling to match the content of following "Types":

(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?

I am trying:

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

But I get an unknown modifier "\" as an error message.

How can I properly match all the types? Thanks for any hints!

Chris
  • 3,311
  • 4
  • 20
  • 34
  • 1
    Possible duplicate of [Warning: preg\_replace(): Unknown modifier '\]'](https://stackoverflow.com/questions/20705399/warning-preg-replace-unknown-modifier) – revo Jun 17 '17 at 17:21
  • 1
    You need to use delimiters in PHP with regexs. http://php.net/manual/en/regexp.reference.delimiters.php You also need to escape special regex characters `()`. – chris85 Jun 17 '17 at 17:34

1 Answers1

1

This should do, assuming there is space after :

preg_match_all('/\((.+?)\): (.*)?/i', $subject, $array, PREG_PATTERN_ORDER);
Mason.Chase
  • 897
  • 1
  • 10
  • 21