| View previous topic :: View next topic |
| Author |
Message |
BCyo+8C4 Voice
Joined: 03 Sep 2006 Posts: 24
|
Posted: Tue Aug 05, 2008 12:22 pm Post subject: replace every "*" in string |
|
|
Hi,
I'm keeping the channels banlist in a text file but got a problem removing the entries from that file as I can't figure out how to escape the asterisks.
sed expects every "*" and "!" to be escaped like "\*" and "\!"
What's the easiest way to replace _every_ "*" with "\*" in a given string? (Replacing just one isn't a problem, but for 5 my code had around 50 lines and is fugly) |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Aug 05, 2008 1:18 pm Post subject: |
|
|
Regsub with a regular expression:
| Code: | | set maskedString [regsub -all -- {\*|!} $oldString {\\\0}] |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BCyo+8C4 Voice
Joined: 03 Sep 2006 Posts: 24
|
Posted: Tue Aug 05, 2008 5:59 pm Post subject: |
|
|
doesn't work
Tcl error [delban]: wrong # args: should be "regsub ?switches? exp string subSpec varName"
Entered the command exactly like you said, only changed the variable names: | Code: | | set maskedString [regsub -all -- {\*|!} $mask {\\\0}] |
also tried with just "{\*}" as expression but that failed as well. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Aug 05, 2008 6:06 pm Post subject: |
|
|
That's odd... which version of tcl are you using?
Most versions of tcl have the varName argument optional. Nevertheless, try using something like this instead then:
| Code: | | regsub -all -- {\*|!} $mask {\\\0} maskedString |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BCyo+8C4 Voice
Joined: 03 Sep 2006 Posts: 24
|
Posted: Tue Aug 05, 2008 6:14 pm Post subject: |
|
|
nvm, just figured it out:
| Code: | | regsub -all {\*|!} $mask {\\\0} mask |
|
|
| Back to top |
|
 |
|