PHP正则表达式 - 对于[[_string_]],返回_string_?

Developing a shorthand parser as part of a client's application. I want to set up a shorthand for creating links similar to mediawiki.

I.E.: [[link_location|link_title]] eventually becomes <a href="link_location">link_title</a>

What I need to do is extract the string from between the brackets so I can process it; there's a bunch of validation and keyword conversion to do before it can go into a link. I'm pretty new to preg_match - I can match the bracketed expression with /\[\[(.*?)\]\]/, but I have no idea how to extract the string from the middle. Can anyone tell me what I'm missing? Or, if I'm going about this all wrong, have mercy and point me in the right direction?

Thanks!

EDIT: I should have clarified: I need to extract the string and process it, so preg_replaceing it directly into a link won't work in this case.

$string = preg_replace("/\[\[([^\|]+)|([^\]]+)\]\]/", "<a href=\"\\1\">\\2</a>", $string);

more

http://php.net/manual/en/function.preg-replace.php

p.s. not tested.


as for edit:

preg_match("/\[\[([^\|]+)\|([^\]]+)\]\]/", $input, $m);

$m[1] -- now is the location
$m[2] -- now is the title

and if you have many:

preg_match_all("/\[\[([^\|]+)\|([^\]]+)\]\]/", $input, $m);

$m[1] -- now contains all location occurrences
$m[2] -- now contains all title occurrences 

[edit] fixed bugs.

$1 gets the first matched group, $2 gets the second etc.

Here's working code for your case:

preg_replace("/\[\[(.*?)\|(.*?)\]\]/", "<a href=\"$1\">$2</a>", "[[link_location|link_title]]");