User:Qwerfjkl (bot)/code/1
Appearance
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
firstChar = title.charAt(0); // Get first character of title
lcFirstChar = firstChar.toLowerCase(); // Lowercase first character of title
restOfTitle = escapeRegExp(title.slice(1)); // Rest of title
titleRegexpString = '[' + escapeRegExp(firstChar) + escapeRegExp(lcFirstChar) + ']' + restOfTitle; // Build regexp for title with case-insensitive first letter
titleRegexpString = titleRegexpString.replace(/ /, "[ _]") // Match spaces and underscores
oldText = oldText.replace(new RegExp('\\[\\[ *(' + titleRegexpString + ') *\\]\\]', 'g'), '$1') // Matches [[title]]
oldText = oldText.replace(new RegExp('\\[\\[ *(?:' + titleRegexpString + ') *\\| *([^\\|\\[\n]+?)\\]\\]', 'g'), '$1') // Matches [[title|piped link]]
oldText = oldText.replace(new RegExp('\\[\\[ *(?:' + titleRegexpString + ')#([^\\|\\[\n]+?) *\\]\\]', 'g'), '{{Section link||$1}}') // Matches [[Title#section]]
oldText = oldText.replace(new RegExp('\\[\\[ *#([^\\|]+?) *\\]\\]', 'g'), '{{Section link||$1}}') // Matches [[#section]]
summ = "Removed [[Help:Self link|link(s) to title]] ([[Wikipedia:WikiProject Check Wikipedia/List of errors#48|CW Error #48]]) (via [[de:Benutzer:Schnark/js/bandersnatch|Bandersnatch]])"
return {text: oldText, summary: summ, minor: true, bot:true};