How to create correct RegEx?

I tried many combinations to create right regex, but I failed.

I want to read this, input:

[@Homer Jay Simpson](id:homer) is a good guy.

and get

Array (
   [0] => "[@Homer Jay Simpson](id:homer)",
   [1] => "Homer Jay Simpson",
   [2] => "homer"
)

thanks!

After a little bit of fiddling, this regex will work for you:

\[@([^\]]+)\]\(id:([^)]+)\)

Used like:

$str = "[@Homer Jay Simpson](id:homer) is a good guy.";
preg_match('#\[@([^\]]+)\]\(id:([^)]+)\)#', $str, $matches);
print_r($matches);

Produces:

Array
(
    [0] => [@Homer Jay Simpson](id:homer)
    [1] => Homer Jay Simpson
    [2] => homer
)

A tip when creating regex patterns, start small and build onto the ends of it. I started with just matching the inside of the square brackets \[@([^\]]+)\] then pieced on the rest of it. Full log here

http://www.phpliveregex.com/p/lAg

preg_match("/\[\@(.*?)\]\(id:(.*?)\)/", $str, $matches);
Var_dump($matches);

This will capture what it between brackets [] and ().
\ makes reges read signs as literal.
.*? means lazy capture anything if any length.