Question: i want to get a particular value from string in php. Following is the string

```
 $string = 'users://data01=[1,2]/data02=[2,3]/*';
 preg_replace('/(.*)\[(.*)\](.*)\[(.*)\](.*)/', '$2', $str);

```

i want to get value of data01. i mean [1,2].

How can i achieve this using `preg_replace`? 

How can solve this ?

Answer: 
preg\_replace is used to replace by regular expression!

I think you want to use `preg_match_all()` to get each data attribute from the string.

The regex you want is:

```
$string = 'users://data01=[1,2]/data02=[2,3]/*';
preg_match_all('#data[0-9]{2}=(\[[0-9,]+\])#',$string,$matches);

print_r($matches);

Array
(
    [0] => Array
        (
            [0] => data01=[1,2]
            [1] => data02=[2,3]
        )

    [1] => Array
        (
            [0] => [1,2]
            [1] => [2,3]
        )

)

```

I have tested this as working.
`preg_replace` is for replacing stuff. `preg_match` is for extracting stuff.

So you want:

```
preg_match('/(.*?)\[(.*?)\](.*?)\[(.*?)\](.*)/', $str, $match);
var_dump($match);

```

See what you get, and work from there.