Code: Select all
set arg_date 15
regsub -nocase {.*<tr\s+bgcolor=\#0099FF><td\s+align=center><FONT SIZE=\'2\'\s+COLOR=\'\#FFFFFF\'\s+face=\'verdana\'>$arg_date(.+)&periuk=.*} $data {\1} data
putquick "PRIVMSG $chan :$data"
Code: Select all
set arg_date 15
regsub -nocase {.*<tr\s+bgcolor=\#0099FF><td\s+align=center><FONT SIZE=\'2\'\s+COLOR=\'\#FFFFFF\'\s+face=\'verdana\'>$arg_date(.+)&periuk=.*} $data {\1} data
putquick "PRIVMSG $chan :$data"
Code: Select all
set arg_date 15
set data "<tr bgcolor=#0099FF><td align=center><FONT SIZE='2' COLOR='#FFFFFF' face='verdana'>$arg_date&periuk="
regsub -nocase {.+<tr\s+bgcolor=\#0099FF><td\s+align=center><FONT SIZE=\'2\'\s+COLOR=\'\#FFFFFF\'\s+face=\'verdana\'>.+&periuk=.*} $data {\1} data
puts "x $data"
Code: Select all
(Tcl) 1 % source regextest.tcl
x <tr bgcolor=#0099FF><td align=center><FONT SIZE='2' COLOR='#FFFFFF' face='verdana'>15&periuk=
(Tcl) 2 %
Code: Select all
set arg_date 15
regsub -nocase {.*<a\s+href=\"b.php\">$arg_date(.+)</b>.*} $data {\1} data
putquick "PRIVMSG $chan :$data"
too much line bro.raider2k wrote:so you want to show everything between <a href="b.php"> and </b>, but not show the rest of it?
please show me example content of your var $data and what it is meant to look like, Ill try to build something for you.
Code: Select all
regexp -- [subst -nocommands -nobackslashes {pattern here}] "text here"
thanks bro. but 15 is a variable can be 13 or 31 or 30. depend on user request.arfer wrote:It can be done by various means. Generally I choose the following method of including a variable within a regexp/regsub pattern
The above solution would require that a dollar symbol ($) never occurs elsewhere within the "text here", otherwise it will obviously be assumed to preceed a variable name.Code: Select all
regexp -- [subst -nocommands -nobackslashes {pattern here}] "text here"
The other alternative would be say to simply exclude the braces and define the pattern with this in mind. For example a \s meaning space would have to be written \\s and square brackets meaning a character set/range would have to be written \[a-z\] etc etc.
People seem to have their favourite methods of dealing with the problem.
Code: Select all
set arg_date 15
set data "<tr bgcolor=#0099FF><td align=center><FONT SIZE='2' COLOR='#FFFFFF' face='verdana'><a href='b.php'>$arg_date&periuk='"
if { [regexp -all -nocase -- {.+\<a href\=\'(.+?)&periuk} $data -> newurl] } {
regsub -nocase -all {\>} $newurl " " newurl
regsub -nocase -all {\'} $newurl "" newurl
set newurl [split $newurl]
}
set phpfile [lindex $newurl 0]
set arg_date_new [lindex $newurl 1]
puts "<a href=\"$phpfile\">$arg_date_new"
Code: Select all
(Tcl) 20 % source regextest.tcl
<a href="b.php">15
(Tcl) 20 %
Instead of this, you need to keep in mind substitution will not take place within { } bracings. So $arg_data is literally just that, not the contents of the variable named arg_data which prefixing the name with $ usually indicates.walker wrote:Code: Select all
regsub -nocase {.*<a\s+href="b.php">$arg_date(.+)</b>.*} $data {\1} data
Code: Select all
set dynamic_regexp ".*<a\s+href="b.php">$arg_date(.+)</b>.*"
regsub -nocase -- $dynamic_regexp $data {\1} data