This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[solved] regexp or regsub im lost

Help for those learning Tcl or writing their own scripts.
Post Reply
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

[solved] regexp or regsub im lost

Post by doggo »

my bot reads from a db and returns the info in channel, only problem is if $line has ...'s and or -_ it displays ok in the channel

but if $line contains spaces instead of ...'s and or -_ i get { $line }

heres an example hope someone can help, been messing around and googleing for ages....

#with the spaces it returns $line with { } either end

Code: Select all

Thanks:(hl) You have been marked as FiLLING ReqId:(64) For:( full  {this is an example} )
and when there is ....'s and -_'s in it doesnt have the { }'s either end

Code: Select all

Thanks:(hl) You have been marked as FiLLING ReqId:(64) For:( full  this.is.an-example )

thanks all hope i gave enough info :)
Last edited by doggo on Wed Jul 14, 2010 9:01 am, edited 1 time in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Somewhere you've confused a tcl-list as a string.

Try using:
regexp {regexp here} [join $var] - var

Wrap a join around your $var-iable inside the regular expression. If this fixes it, then you know you have a tcl-list vs string issue. Don't use this as a permanent fix, find the issue and correct it. This is merely to test if indeed it is a list being treated as a string causing the problem.

Report back if you need more help ;)
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

Code: Select all

regsub -all {\{} $search "" search_clean
regsub -all {\}} $search_clean "" search_even_clean
fixed it :)
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

That's not so much a fix as it is a band-aid. You should avoid doing a filter like that unless all else fails. Whenever you declare something as a list, each list element is separated by what is in {}. So if you declare set something [lindex $var 0], you'd get the first bit in {}. But if you don't output this correctly, the {} remains in the text. This is why you use join, to turn it back into a string, thus dropping the {} from the text automatically.

There is an article "How to write scripts that won't choke on special chars", but my net is too crappy atm to find it. :S
Post Reply