egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HELP! Regexp/Regsub

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
maphex
Voice


Joined: 10 Feb 2012
Posts: 9

PostPosted: Tue Dec 04, 2012 9:22 pm    Post subject: HELP! Regexp/Regsub Reply with quote

So what im trying to do here is make a trigger that is based on a SQL entry.
So the first !(.*) will be the trigger.
Then I want the next (.*) to be the search term(s).

Everything works fine if the search term is one word but if the term is broken by a space like !searchchan search words here the script fails.

So I need to make it take the second (.*) and extend to the end of the line and save it as a var. Then the regsub will then take it and break it into usable content the rest of the script can use.

Code:
    bind pubm - * bind_search
    proc bind_search {nick uhost handle channel text} {

      filter_mirc_codes
   set regexp {^!(.*) (.*) *$}
   if {[regexp -nocase -- $regexp $text -> searchchan search]} {
    
   regsub -all -- {\*} $search % search
   set searchvar [list]
   foreach word [split $search] {
   lappend searchvar db.`searchcolum` like '%[mysqlescape $word]%'"
   }
   
   do sql stuff like getting results
        where [join $searchvar " AND " ]
   AND SearchChannel LIKE '#%$searchchan%'
   }
}


Added this just in case someone need to know theproc for the filter_mirc_codes

Code:
    proc filter_mirc_codes {} {
      upvar text text
      regsub -all -- "(\002|\017|\026|\037|\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?)"  $text "" text
}


Big thanks in advance! I am open to other options that maybe fast or cleaner to the way I am doing it.
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Tue Dec 04, 2012 10:15 pm    Post subject: Reply with quote

Why not simply use [split $text] on the text.
Then [lindex $text 0] would be the first word and [lrange $text 1 end] would be all the other words, still as a list.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
maphex
Voice


Joined: 10 Feb 2012
Posts: 9

PostPosted: Wed Dec 05, 2012 2:22 am    Post subject: Reply with quote

Could you provide me with an example? I understand a little better when its laid out and can see how it works? Thanks for the fast response!
Back to top
View user's profile Send private message
Nimos
Halfop


Joined: 20 Apr 2008
Posts: 80

PostPosted: Wed Dec 05, 2012 12:00 pm    Post subject: Reply with quote

Code:

   if {[regexp -nocase -- {^!.* .*$} $text]} {
     
      set trigger [lindex [split $text] 0]
      set search [lrange [split $text] 1 end]
   
      regsub -all -- {\*} $search % search
     
      set searchvar [list]
      foreach word $search {
         lappend searchvar db.`searchcolum` like '%[mysqlescape $word]%'"
      }
   
      do sql stuff like getting results
        where [join $searchvar " AND " ]
   AND SearchChannel LIKE '#%$searchchan%'
   }
Back to top
View user's profile Send private message
maphex
Voice


Joined: 10 Feb 2012
Posts: 9

PostPosted: Wed Dec 05, 2012 3:57 pm    Post subject: Reply with quote

Thanks for all the help. I got it working with some modifications to the code to not use a pubm and used a regular bind pub and still used the split text that Nimos provided.

I decided against the regexp method because of overlapping binds using pubm unless there is something i missed to stop this
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber