| View previous topic :: View next topic |
| Author |
Message |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Tue Dec 04, 2012 9:22 pm Post subject: HELP! Regexp/Regsub |
|
|
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 |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Tue Dec 04, 2012 10:15 pm Post subject: |
|
|
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 |
|
 |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Wed Dec 05, 2012 2:22 am Post subject: |
|
|
| 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 |
|
 |
Nimos Halfop
Joined: 20 Apr 2008 Posts: 80
|
Posted: Wed Dec 05, 2012 12:00 pm Post subject: |
|
|
| 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 |
|
 |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Wed Dec 05, 2012 3:57 pm Post subject: |
|
|
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 |
|
 |
|