I'm trying to make a search string, which can accept a query like this:

```
$string = 'title -launch category:technology -tag:news -tag:"outer space"$';

```

Here's a quick explanation of what I want to do:

```
$ = suffix indicating that the match should be exact
" = double quotes indicate that the multi-word is taken as a single keyword
- = a prefix indicating that the keyword is excluded

```

Here's my current parser:

```
$string = preg_replace('/(\w+)\:"(\w+)/', '"${1}:${2}', $string);
$array = str_getcsv($string, ' ');

```

I was using this above code before, but it doesn't work as intended with the keywords starting on searches like **-tag:"outer space"**. The code above doesn't recognize strings starting with - character and breaks the keyword at the whitespace between the **outer** and **space**, despite being enclosed with double quotes.

EDIT: What I'm trying to do with that code is to preg\_replace -tag:"outer space" into "-tag:outer space" so that they won't be broken when I pass the string to str\_getcsv().