fork(1) download
  1. <?php
  2.  
  3. $re = '~"(?:\\\\.|[^\\\\"])*"|\'(?:\\\\.|[^\\\\\'])*\'|[^\s"\']+~';
  4. $str = 'Lorem ipsum ("dolor sit amet") consectetur "adipiscing \\"elit" dolor \'something \\\'here\'';
  5. preg_match_all($re, $str, $matches);
  6. print_r($matches[0]);
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Lorem
    [1] => ipsum
    [2] => (
    [3] => "dolor sit amet"
    [4] => )
    [5] => consectetur
    [6] => "adipiscing \"elit"
    [7] => dolor
    [8] => 'something  \'here'
)