Q:

regex not capturing square braquets

I am converting some wiki text to markdown. The wiki links are in format:
[[url|text]]

and I am having problems to find a regex to catch it.
The regex i am trying is (\[\[(.*\|[^\]]*)\]\]) (live example: http://regex101.com/r/nW2zG7/1) 
So in the following text:
Clicking this will echo out the code and the result in the [[http://getfirebug.com|Firebug]]     
debugging plugin for [[http://getfirefox.com|Firefox]]. 
If you don\'t have that plugin or Firefox, a similar 
console should be visible at the bottom of the page. This is a poor substitute for 
Firebug, so I highly recommend installing both [[http://getfirefox.com|Firefox]] and 
[[http://getfirebug.com|Firebug]] when viewing this tutorial.

It fails to catch the text of that link, and catches all this:
http://getfirebug.com|Firebug]] debugging plugin for [[http://getfirefox.com|Firefox]]. If you don\'t have that plugin or Firefox, a similar console should be visible at the bottom of the page. This is a poor substitute for Firebug, so I highly recommend installing both [[http://getfirefox.com|Firefox]] and [[http://getfirebug.com|Firebug
I supose I am doing something wrong here: |[^\]]*)
In the end I will run this regex in javascript like:
markdown = markdown.replace(/(\[\[(.*\|.*)\]\])/g, function(string, submatch1, submatch2){
    var parts = submatch2.split('|');
    return '[' + parts[1] + '](' + parts[0] + ')';
});

A:

The problem is the first .* in your regex which is greedy and matches all the character until the last | (not first). You should replace the .* with [^\|]* which is all the characters except |
That should match correctly (\[\[([^\|]*\|[^\]]*)\]\])

