Q: php newbie problem: regex i'm sorry i've already asked for this but couldn't find a solution yet :(
here's my string: (as you can see it has linebreaks)
Webname:    [webname]
Username:   [username]
IP:     [IP]

i need to read out the values inside the square brackets.
here's my code:
    $pattern = '/\[(.|\n)+?\]/'; // i've used the same syntax for my asp projects, always worked
    preg_match($pattern, $txt, $matches, PREG_OFFSET_CAPTURE);
    echo "matches:".count($matches)."\n\n";
    foreach ($matches as $match) 
    {
        echo $match[0]."\n";
    }

i'm getting only 2 matches: [webname] and e (???)
i'm fiddling with this for hours now and can't find out what's wrong ..
any ideas?
thanks

A: Looks more complicated than it has to be. Line breaks don't play any role here.
$pattern = '/\[(.+?)\]/';
preg_match_all($pattern, $txt, $matches);

print_r($matches);

gives
Array
(
    [0] => Array
        (
            [0] => [webname]
            [1] => [username]
            [2] => [IP]
        )

    [1] => Array
        (
            [0] => webname
            [1] => username
            [2] => IP
        )

)

So the values would be in $matches[1]. If you want the values including the brackets ($matches[0]), you can also omit the parenthesis in the pattern.

A: The first capture group, in your case there is only one, is in $matches[1]

A: Try something like
$pattern = '/\[([^\]]+)\]/';

and use preg_match_all() to get all matches.

A: Try this
$values = array();

foreach (explode("\n", $text) as $line) {
    if (preg_match('/([^:]++):[^\s]*+(.*+)/', $line, $match)) {
        $values[$match[1]] = $match[2];
    }
}

var_dump($values);

