| View previous topic :: View next topic |
| Author |
Message |
garung Voice
Joined: 26 Oct 2005 Posts: 9
|
Posted: Sun Aug 31, 2008 1:11 pm Post subject: regexp question |
|
|
Can someone help me how to skip word like I'll . it's , she's ... in $text? thanks
while {[regexp -indices -start $pos {[^[:punct:]\s]+} $text match]} {
lappend words $match
lassign $match -> pos
incr pos
} |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Aug 31, 2008 4:06 pm Post subject: |
|
|
| Code: | <speechles> .tcl set a "I'll . it's , she's ..."
<bot> Tcl: I'll . it's , she's ...
<speechles> .tcl set b [string map {"." "" "?" "" "," ""} $a]
<bot> Tcl: I'll it's she's
<speechles> .tcl set c [join [split $b]]
<bot> Tcl: I'll it's she's
|
Like that? Part c, the join and split is there to eliminate over spaced fields and return to the string to nomal single spaces. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
garung Voice
Joined: 26 Oct 2005 Posts: 9
|
Posted: Sun Aug 31, 2008 5:12 pm Post subject: |
|
|
| speechless, it's tnot that, i mean skip these words(he's she's it's) so that they dont replace them with asterisks |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Aug 31, 2008 7:02 pm Post subject: |
|
|
| garung wrote: | | speechless, it's tnot that, i mean skip these words(he's she's it's) so that they dont replace them with asterisks |
| Code: | <speechles> .tcl set a [asterize "this, is a word. this is a question?"]
<bot> Tcl: ****, ** * ****. **** ** * ********?
<speechles> .tcl set a [asterize "he's got this. she's got that. you've got those."]
<bot> Tcl: **'* *** ****. ***'* *** ****. ***'** *** *****. |
| Code: | proc asterize {text} {
set asterisktext ""
foreach word [split $text] {
set asteriskword ""
foreach char [split $word ""] {
if {[string match *$char* "`~!@#$%^&()\[\]\{\}:;'\"<>\?,."]} {
append asteriskword $char
} else {
append asteriskword "*"
}
}
append asterisktext "$asteriskword "
}
return [string trim $asterisktext]
} |
You mean like this? _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
garung Voice
Joined: 26 Oct 2005 Posts: 9
|
Posted: Sun Aug 31, 2008 11:03 pm Post subject: |
|
|
You're so cool! thanks speechles  |
|
| Back to top |
|
 |
|