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 the wrong tool, I have used `preg_match_all()` in case you need that other item later and trimmed down your regex to capture the part of the string you are looking for.

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

    print_r($match);

/*
     print_r($match) output:

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

    echo "Your match: " . $match[1][0];

    ?>

```

This enables you to have the captured characters or the matched pattern , so you can have `[1,2]` or just `1,2`
`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.