XXXX redacted: Difference between revisions

Added AutoHotkey
(Added AutoHotkey)
Line 284:
return redactor's outputText
end redact</lang>
 
=={{header|AutoHotkey}}==
No Complex Unicode!
<lang AutoHotkey>str = Tom? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so tom.
words := ["Tom", "tom"]
opts := ["wsn", "win", "psn", "pin", "pso", "pio"]
for i, word in words
{
result .= "Redact '" word "'`n"
for j, opt in opts
result .= opt "`t" redact(str, word, opt) "`n"
result .= "`n"
}
MsgBox, 262144, , % result
return
redact(str, word, opt){
if InStr(opt, "w") ; Whole word
a := "(^|[^-])\K\b", z := "\b(?!-)"
if InStr(opt, "o") ; Overkill
a .= "\b[\w\-]*", z := "[\w\-]*\b" z
if InStr(opt, "i") ; Case insensitive
i := "i)"
ndle := i a "\Q" word "\E" z
while pos := RegExMatch(str, ndle, mtch, A_Index=1?1:pos+StrLen(mtch))
{
rplc := ""
loop % StrLen(mtch)
rplc .= "X"
str := RegExReplace(str, ndle, rplc,, 1)
}
return str
}</lang>
{{out}}
<pre>Redact 'Tom'
wsn XXX? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so tom.
win XXX? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so XXX.
psn XXX? XXXs bottom tomato is in his stomach while playing the "XXX-tom" brand tom-toms. That's so tom.
pin XXX? XXXs botXXX XXXato is in his sXXXach while playing the "XXX-XXX" brand XXX-XXXs. That's so XXX.
pso XXX? XXXX bottom tomato is in his stomach while playing the "XXXXXXX" brand tom-toms. That's so tom.
pio XXX? XXXX XXXXXX XXXXXX is in his XXXXXXX while playing the "XXXXXXX" brand XXXXXXXX. That's so XXX.
 
Redact 'tom'
wsn Tom? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so XXX.
win XXX? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so XXX.
psn Tom? Toms botXXX XXXato is in his sXXXach while playing the "Tom-XXX" brand XXX-XXXs. That's so XXX.
pin XXX? XXXs botXXX XXXato is in his sXXXach while playing the "XXX-XXX" brand XXX-XXXs. That's so XXX.
pso Tom? Toms XXXXXX XXXXXX is in his XXXXXXX while playing the "XXXXXXX" brand XXXXXXXX. That's so XXX.
pio XXX? XXXX XXXXXX XXXXXX is in his XXXXXXX while playing the "XXXXXXX" brand XXXXXXXX. That's so XXX.</pre>
 
=={{header|C}}==
299

edits