Search and Split the found Text

I’m trying to find a place from the input text and set the number after the = as a variable. Unfortunately, what is wrong output

With my code, the maxresults variable returns "i" as the result. But it should be 20.

Code:

bind pub "-|-" !a pub:a
proc pub:a { nick host handle channel text } {

    set maxresults ""
    if {[regexp -nocase {max=} $text]} {
    set maxresults0 [lindex [split $text max=] 1]
    set maxresults [lindex $maxresults0 0]
    putnow "PRIVMSG $channel :maxresults: $maxresults"
    }
}

Input:
!a Remix find now country=german max=20 currency=euro

Output:
maxresults: i

but it should be:
maxresults: 20

>Solution :

You can do the whole job with regexp

if {[regexp -nocase {max=(\d+)} $text - maxresults]} {
    putnow "PRIVMSG $channel :maxresults: $maxresults"
}

See the documentation at http://www.tcl-lang.org/man/tcl8.6/TclCmd/regexp.htm

Leave a Reply