I have a working pattern
/[^\s"']+|"([^"]*)"|'([^']*)'|/
that splits single words or phrases (in double or single quotes) separated by a space into an matches array. I want to modify the pattern to allow “+” sign or “-” sign to appear at the beginning of the word/phrase so preg_match_all dont splits the + or – into a separate match ie:
guide -"test * of" +'guide'
I want it to split into below matches
[0] => Array
(
[0] => guide
[1] => -"test * of"
[2] => +'guide'
)
Thanks in advance.
Try following pattern:
/[+-]?([^\s"']+|"([^"]*)"|'([^']*)')/