Input:
Search_Pattern:
RX_ON:
Flags:
Replace_Pattern:
…is a function:
(?)
with arguments:
Controls:
Loop:
The Function (edit it if you want):
window.regplax = function () { try { var form = document.forms[0] , input = form.Input , output = input , Flags = form.Flags.value , pattern = form.RX_ON.checked ? form.Search_Pattern.value : pattern.replace( /(\W)/g , '\\$1' ) // ^ using RX for disabling RX. funny. , searchRg = new RegExp( pattern , Flags ) , replaceSt = form.ptrn_is_fnc.checked // HAHAHAHA, deep dark practices follows: ? eval ( "new Function(\"" + form.ptrn_is_fnc_params.value.split(/,\s*/).join("\",\"") + "\",\"" + form.Replace_Pattern.value.replace(/(")/g,'\\$1').replace(/\n/g,' ') + "\")" ) // p.s.: HAHAHAHA. : form.Replace_Pattern.value , buff = input.value.replace( searchRg , replaceSt ) ; if ( form.loop.checked ) { var lastVal ; while( buff.search(searchRg) > -1 ) // searchRg.test(buff) behaves strange in IE6 and O9. gotta look at it { lastVal = buff ; buff = buff.replace( searchRg , replaceSt ) ; if ( lastVal === buff ) throw new Error( 'Potentially (?) infinite loop terminated.' ) } } ; output.value = buff } catch ( e ) { alert( e + '\n -- regplax function' ) } }
Hints
Undo = ctrl+z in focused textarea (in most browsers; it may behave differently but generally it works. wee!)
For highliting matches use
regexpal
. Gotta grab that & exploit it here }:)
MDC:replace