$re = '/(?<!\\\\) # Check it was not escaped with a \
(?<img_all>
\!\[(?<img_alt>.+?)\] # image alternative text, i.e. the text used when the image does not
(?:
(?:
[ ]? # possibly followed by some spaces
(?:\n[ ]*)? # and a new line with some space
\[(?<img_id>.*?)\] # with the link id in brackets, but may be empty
)
|
(?:
(?:
\(
[ \t]*
<(?<img_url> # link url within <>; or
.+?
)>
[ \t]* # possibly followed by some spaces or tabs
(?:
(?<img_title_container>[\'"]) # Title is surrounded ether by double or single quotes
(?<img_title>.*?) # actual title, but could be empty as in ""
\g{img_title_container} # make the sure enclosing mark balance
)?
[ \t]*
\)
)
|
(?:
\(
[ \t]*
(?<img_url> # link url within <>; or
(?:((?!["\']).)*+|.*)
)
[ \t]*
(?:
(?<img_title_container>[\'"]) # Title is surrounded ether by double or single quotes
(?<img_title>.*?) # actual title, but could be empty as in ""
\g{img_title_container} # make the sure enclosing mark balance
)?
[ \t]*
\)
)
)
)
[ \t]*
(?<!\\\\)
\{
[[:blank:]\h]*
(?<img_attr>.+?)
[[:blank:]\h]*
\}
)/mxJ';
$str = 'This is an {.class #inline-img}.
.jpg\'Title here\') {.class #inline-img} and some text after
 {.class #inline-img}
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php