从自定义标记中提取链接的简单正则表达式[重复]

This question already has an answer here:

I am not at all experienced with regex, so please bear with me.

I am building a simple content markup language for an admin.

I want for the admin user to be able to create a link by specifying the following within an admin;

[link="http://www.google.com"]Google[/link]

From this, I need to basically get the value XXX in [link="XXX"] and the value between [link="abcd"]XXX[/link]. So for the above example I'd want to extract 'http://www.google.com' and 'Google'.

I am working with PHP.

Any help would be greatly appreciated.

</div>

you can use preg_match like this

$url = '[link="http://www.google.com"]Google[/link]';   
preg_match('/\[link=\"(.+?)\"\](.+?)\[\/link\]/', $url, $matches);
print_r($matches);

$matches will contain

Array
(
    [0] => [link="http://www.google.com"]Google[/link]
    [1] => http://www.google.com
    [2] => Google
)