Actually, now that I see Jang's method, it is simpler for this case. If your regular expression has capturing groups, you have to use my method. For example, let's say that you wanted to capture the citations without the brackets. Then, you would use this:
var pgfText = "Hello fans [[Dante, #712]] and another one [[DuçanÌsídõrâ, #312]].";
var citations = getCitations (pgfText);
alert(citations);
function getCitations (pgfText) {
// Regular expression to isolate the citations. var regex = /\[\[([^\]]+)\]\]/g; // Array to store the citations. var citations = [], result; // Execute the regular expression. while (result = regex.exec (pgfText)) { // Push the result onto the array. citations.push (result[1]); } // Return the array return citations;
}
Notice that I moved the parenthesis to exclude the enclosing square brackets.
Also note that if you don't need to capture any subparts of the string, you don't need the parenthesis at all in your regular expression.
Rick