https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=User%3ATopbanana%2FregexReplace.js Benutzer:Topbanana/regexReplace.js - Versionsgeschichte 2025-07-29T20:02:48Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.11 https://de.wikipedia.org/w/index.php?title=Benutzer:Topbanana/regexReplace.js&diff=93650030&oldid=prev Topbanana: AZ: Die Seite wurde neu angelegt: /* This is a slightly modified copy of User:Gerbrant/edit/regexReplace.js as I couldn't make the … 2011-09-14T16:57:31Z <p><a href="/wiki/Hilfe:Zusammenfassung_und_Quellen#Auto-Zusammenfassung" title="Hilfe:Zusammenfassung und Quellen">AZ</a>: Die Seite wurde neu angelegt: /* This is a slightly modified copy of <a href="/w/index.php?title=Benutzer:Gerbrant/edit/regexReplace.js&amp;action=edit&amp;redlink=1" class="new" title="Benutzer:Gerbrant/edit/regexReplace.js (Seite nicht vorhanden)">User:Gerbrant/edit/regexReplace.js</a> as I couldn&#039;t make the …</p> <p><b>Neue Seite</b></p><div>/*<br /> This is a slightly modified copy of [[User:Gerbrant/edit/regexReplace.js]] as I couldn&#039;t<br /> make the original do what I wanted.<br /> */<br /> <br /> <br /> document.write(&quot;&lt;style&gt;span.GerbrantEditRegexReplaceHit{font-weight:bold;background:lightsteelblue}span.GerbrantEditRegexReplaceHitOff{font-weight:bold;background:mistyrose}span.GerbrantEditRegexReplaceMaskFailed{font-weight:normal;color:red}&lt;/style&gt;&quot;);<br /> <br /> function createRegexControls()<br /> {<br /> var lang, textBox = document.getElementById(&quot;wpTextbox1&quot;);<br /> if(!textBox) return;<br /> <br /> str = {<br /> finished: &quot;Finished; $1 items were replaced.&quot;,<br /> finished2: &quot;Finished; $1 out of $2 items were replaced.&quot;,<br /> notFound: &quot;Requested text was not found.&quot;,<br /> replace: &quot;Find&quot;,<br /> replaceSel: &quot;Replace&quot;,<br /> errorNoCheckBox: &quot;Cannot find the corresponding checkbox.&quot;,<br /> textHasChanged: &quot;Warning! The text has changed after &#039;Replace...&#039; was clicked. These changes will be lost during replacement. Do you want to continue?&quot;,<br /> looksLikeFunction: &quot;Warning! The text you intend to use to replace the matched text looks like a JavaScript function. Are you really sure you want to use this as replacement text, and not as a replacement function?&quot;,<br /> maskFailed: &quot;Mask failed: $1&quot;,<br /> useRepFun: &quot;&lt; function &gt;&quot;<br /> };<br /> <br /> <br /> var mask, regex, text, minFrag = 30, minDel = 10, repFun;<br /> <br /> var results = document.createElement(&quot;DIV&quot;);<br /> var tbRegex = document.createElement(&quot;INPUT&quot;);<br /> tbRegex.id = &quot;tbRegex_SearchTextBox&quot;;<br /> <br /> var hl = document.createElement(&quot;INPUT&quot;);<br /> hl.type = &quot;checkbox&quot;;<br /> <br /> var rep = document.createElement(&quot;DIV&quot;);<br /> rep.style.display = &quot;none&quot;;<br /> rep.style.whiteSpace = &quot;nowrap&quot;;<br /> <br /> function returnTrue(){ return true; }<br /> <br /> function evalError(e){ alert(e.message); }<br /> <br /> function getMaskAndRegex(t)<br /> {<br /> var p = t.indexOf(&quot;**&quot;), r;<br /> if(p &lt; 0) return [returnTrue, t];<br /> else<br /> {<br /> try{ eval(&quot;r=&quot; + t.slice(0, p)) }<br /> catch(x){ evalError(x); r = returnTrue; }<br /> return [r, t.slice(p + 2)];<br /> }<br /> }<br /> <br /> function findMatches()<br /> {<br /> var m = [], r = [], i = 0;<br /> text = textBox.value;<br /> <br /> var t = text.replace(regex, function(a)<br /> {<br /> try<br /> {<br /> if(!mask.apply(null, arguments)) return a;<br /> }<br /> catch(e)<br /> {<br /> m.push(a + &#039; \u0001span class=&quot;GerbrantEditRegexReplaceMaskFailed&quot;&gt;(&#039; + str.maskFailed.replace(&quot;$1&quot;, e.message) + &#039;)\u0001/span&gt;&#039;);<br /> return &quot;\u0001&quot;;<br /> }<br /> m.push(a);<br /> return &quot;\u0001&quot;;<br /> }).split(&quot;\u0001&quot;);<br /> <br /> if(m.length == 0)<br /> {<br /> results.innerHTML = str.notFound;<br /> return;<br /> }<br /> <br /> if(t[0].length &gt; minFrag + minDel)<br /> {<br /> r.push(&quot; \u2026 &quot;);<br /> r.push(t[0].slice(-minFrag));<br /> }<br /> else<br /> r.push(t[0]);<br /> while(true)<br /> {<br /> r.push(&#039;\u0001span class=&quot;GerbrantEditRegexReplaceHit&quot;&gt;\u0001input type=&quot;checkbox&quot; checked id=&quot;Gerbrant-errCB&#039;);<br /> r.push(i);<br /> r.push(&#039;&quot; onclick=&quot;Gerbrant.edit.regexReplace.toggleCB(this)&quot;&gt;&#039;);<br /> r.push(m[i]);<br /> r.push(&#039;\u0001/span&gt;&#039;);<br /> if(++i &gt;= m.length) break;<br /> if(t[i].length &gt; 2 * minFrag + minDel)<br /> {<br /> r.push(t[i].slice(0, minFrag));<br /> r.push(&quot; \u2026 &quot;);<br /> r.push(t[i].slice(-minFrag));<br /> }<br /> else<br /> r.push(t[i]);<br /> }<br /> if(t[i].length &gt; minFrag + minDel)<br /> {<br /> r.push(t[i].slice(0, minFrag));<br /> r.push(&quot; \u2026 &quot;);<br /> }<br /> else<br /> r.push(t[i]);<br /> <br /> rep.style.display = &quot;&quot;;<br /> onResize();<br /> results.innerHTML = r.join(&quot;&quot;).replace(<br /> /&amp;/g, &quot;&amp;amp;&quot;).replace(<br /> /&lt;/g, &quot;&amp;lt;&quot;).replace(<br /> /\u0001/g, &quot;&lt;&quot;).replace(<br /> /\n[ \t]/g, &quot;\n&amp;nbsp;&quot;).replace(<br /> /[ \t](?=[ \t])/g, &quot;&amp;nbsp;&quot;).replace(<br /> /\n/g, &quot;&lt;br&gt;&quot;);<br /> }<br /> <br /> function getRegexAndFind()<br /> {<br /> mask = getMaskAndRegex(tbRegex.value);<br /> regex = new RegExp(mask[1], hl.checked ? &quot;g&quot; : &quot;ig&quot;);<br /> mask = mask[0];<br /> findMatches();<br /> }<br /> <br /> var ok = document.createElement(&quot;INPUT&quot;);<br /> ok.type = &quot;button&quot;;<br /> ok.value = str.replace;<br /> ok.onclick = getRegexAndFind;<br /> ok.id = &quot;tbRegex_FindButton&quot;;<br /> <br /> var div = document.createElement(&quot;DIV&quot;);<br /> div.style.whiteSpace = &quot;nowrap&quot;;<br /> div.appendChild(tbRegex);<br /> div.appendChild(hl);<br /> div.appendChild(ok);<br /> <br /> var tbReplace = document.createElement(&quot;INPUT&quot;);<br /> tbReplace.id = &quot;tbRegex_ReplaceTextBox&quot;;<br /> <br /> <br /> var chkJS = document.createElement(&quot;INPUT&quot;);<br /> chkJS.type = &quot;checkbox&quot;;<br /> <br /> function doReplace()<br /> {<br /> var rjs = chkJS.checked, i = 0, j = 0, r, nt, ohno = false;<br /> if(text != textBox.value) if(!confirm(str.textHasChanged)) return;<br /> r = tbReplace.value;<br /> if(rjs)<br /> if(r == str.useRepFun) r = repFun;<br /> else try{ eval(&quot;r=&quot; + r); }<br /> catch(x){ evalError(x); return; }<br /> else if(r == str.useRepFun || /^\s*function\s*\([0-9A-Za-z$_, ]*\)\s*\{/.test(r)) if(!confirm(str.looksLikeFunction)) return;<br /> try<br /> {<br /> nt = text.replace(regex, function(a)<br /> {<br /> try{ if(!mask.apply(null, arguments)) return a; }catch(e){/* mask failed; assume true */}<br /> var c = document.getElementById(&quot;Gerbrant-errCB&quot; + i++);<br /> if(c)<br /> if(c.checked)<br /> {<br /> j++;<br /> if(rjs)<br /> return r.apply(null, arguments);<br /> else return r;<br /> }<br /> else return a;<br /> else ohno = true;<br /> });<br /> }<br /> catch(e)<br /> {<br /> alert(e.message);<br /> return;<br /> }<br /> if(ohno)<br /> {<br /> alert(str.errorNoCheckBox);<br /> return;<br /> }<br /> if(j &lt; i) results.innerHTML = str.finished2.replace(&quot;$1&quot;, j).replace(&quot;$2&quot;, i);<br /> else results.innerHTML = str.finished.replace(&quot;$1&quot;, j);<br /> rep.style.display = &quot;none&quot;;<br /> textBox.value = nt;<br /> }<br /> <br /> var finish = document.createElement(&quot;INPUT&quot;);<br /> finish.type = &quot;button&quot;;<br /> finish.value = str.replaceSel;<br /> finish.onclick = doReplace;<br /> <br /> rep.appendChild(tbReplace);<br /> rep.appendChild(chkJS);<br /> rep.appendChild(finish);<br /> <br /> textBox.parentNode.insertBefore(div, textBox);<br /> textBox.parentNode.insertBefore(results, textBox);<br /> textBox.parentNode.insertBefore(rep, textBox);<br /> <br /> function onResize()<br /> {<br /> finish.style.height = ok.style.height = tbRegex.offsetHeight + &quot;px&quot;;<br /> tbRegex.style.width = textBox.offsetWidth - ok.offsetWidth - hl.offsetWidth - 14 + &quot;px&quot;;<br /> tbReplace.style.width = textBox.offsetWidth - finish.offsetWidth - chkJS.offsetWidth - 14 + &quot;px&quot;;<br /> }<br /> onResize();<br /> hookEvent(&quot;resize&quot;, onResize);<br /> }</div> Topbanana