Question: I have a string that contains some values I need to extract. Each of these values is surrounded by a common character. 

What is the most efficient way to extract all of these values into an array?

For example, given the following string:

```
stackoverflowis%value1%butyouarevery%value2%

```

I would like to get an array containing `value1` and `value2`

Answer: 
```
$s = "stackoverflowis%value1%butyouarevery%value2%";
preg_match_all('~%(.+?)%~', $s, $m);
$values = $m[1];

```

[preg\_match\_all](http://php.net/manual/en/function.preg-match-all.php)
```
$str = "stackoverflowis%value1%butyouarevery%value2%";
preg_match_all('/%([a-z0-9]+)%/',$str,$m);
var_dump($m[1]);

array(2) { [0]=> string(6) "value1" [1]=> string(6) "value2" }

```