Question: I was playing with PHP today creating a small language (just for fun), but I encountered a problem:

**How can I select between matching brackets?**

My template string:

```
for(items as item){ // this bracket
  if(some_condition){
      // do stuff

  } // my regex stops here

} // and this bracket

```

I used [this regex](http://www.regexr.com/39epn) `[\w]+\([ \w]+\){([\s\n\r\t/\w(){}]+?)}`, but it stop when finds the first closed bracket.

**How can I make it select everything between his matching brackets?:**

for(items as item){ // this bracket

```
if(some_condition){
      // do stuff

  } // my regex stops here

```

} // and this bracket

Then I will compile what's in the `for` separately.

PS: Please don't post comments like "don't bother doing this" or "don't reinvent the wheel". It is just for learning purposes.

Answer: 
I'm not sure, but you might want to look at your logic. Don't you mean to do:

```
DELETE FROM fc_product_quantities WHERE product_id=18 AND (color_id NOT IN (9,1) OR size_id NOT IN (23,24))

```

This is just a guess, because all the AND's might leave you with nothing to delete.
Your current query exclude to much rows from delete.

```
DELETE
FROM fc_product_quantities
WHERE product_id=18
AND color_id NOT IN (9,1)
AND size_id NOT IN (23,24)

```

Example with a row like this : 

```
Array
(
  [pid] => 18
  [color] => 9
  [size] => 50
)

```

This row will not be deleted because you exclude value 9 in `color_id`.
This will work : 

```
DELETE
FROM fc_product_quantities
WHERE product_id = 18
AND (
    (color_id != 9 AND size_id != 23)
    OR
    (color_id != 1 AND size_id != 24)
)

```