var input = document.getElementById('textinput').value;
var lines = input.split('\n');
var output = '';
$.each(lines, function(key, line) {
for(var iii=0; iii<=key; iii++) //for each line
{
var filenameRegex = /^\* \[\[Media:(.+?)(\|)/;
var results = lines[iii].match(filenameRegex);
var filename;
console.log('lines[iii]= '+lines[iii]);
if(results!==null && results.length!== 0)
{
output += lines[iii].replace(filenameRegex,'$1');
}
}
I try hard but the output is always output += lines[iii].replace(filenameRegex,'$1$2')
even though I only want $1
Example input: * [[Media:importantstuff|unimportantstuff]]
Expected output: importantstuff
Actual output: importantstuffunimportantstuff]]