Pixelz Voice

Joined: 15 Jun 2005 Posts: 24 Location: EFnet
|
Posted: Fri Oct 01, 2010 5:28 am Post subject: substitute.tcl v1.0, sed-style text substitution (s/foo/bar) |
|
|
This script provides sed style text subsitution, with full regular expression support. Use ".chanset #chan +substitute" to enable the script in a channel.
Notes:
Flags (i.e. global, case-insensitive) aren't supported directly in the syntax, however Tcl metasyntax can still be used. Expressions default to global/all, case-sensitive. Note that it's not possible to turn on or off global matching via metasyntax, this is because of a limitation in Tcl.
Usage examples:
| Quote: | Basic usage
<nick> Hello, World!
<nick> s/World/Everyone
<bot> Nick meant: "Hello, Everyone!" |
| Quote: | With : instead of /
<nick> Hello, World!
<nick> s:World:Everyone
<bot> Nick meant: "Hello, Everyone!" |
| Quote: | Removing text
<nick> Hello, World!
<nick> s/,/
<bot> Nick meant: "Hello World!" |
| Quote: | Substitutions can be stacked indefinately
<nick> Hello, World!
<nick> s/l/w/s/o/u
<bot> Nick meant: "Hewwu, Wurwd!" |
| Quote: | You can keep stacking over multiple messages
<nick> Hello, World!
<nick> s/World/Everyone
<bot> Nick meant: "Hello, Everyone!"
<nick> s/Everyone/Friday
<bot> Nick meant: "Hello, Friday!" |
| Quote: | Regular expression
<nick> Hello, World!
<nick> s/[A-Z]/Y
<bot> Nick meant: "Yello, Yorld!" |
| Quote: | More regular expression
<nick> Hello, World!
<nick> s/\S/x
<bot> Nick meant: "xxxxxx xxxxxx" |
| Quote: | Metasyntax in action, turning on case insensitive matching:
<nick> Aaa Bbb
<nick> s/(?i)a/x/s/(?i)b/y
<bot> Nick meant: "xxx yyy" |
| Quote: | Substitution guru:
<nick> :p
<nick> s/:/abc/s/p/defg/s/[ce]/^/s/d/o/s/a/\/s:g:/:s/b/(/s/f/)
<bot> Nick meant: "\(^o^)/" |
Download: substitute-1.0.tcl _________________ Pixelz @ EFnet, freenode, QuakeNet, Undernet
Last edited by Pixelz on Tue Oct 05, 2010 12:01 pm; edited 1 time in total |
|