| View previous topic :: View next topic |
| Author |
Message |
walker Voice
Joined: 03 Sep 2009 Posts: 6
|
Posted: Thu Sep 03, 2009 1:14 am Post subject: regsub -nocase {} help |
|
|
i have code like this:
| Code: | 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"
|
why it's not working?? i think i wrong the code between \'verdana\'> and (.+)&periuk=. please help me. thank you.... |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Thu Sep 03, 2009 1:53 am Post subject: |
|
|
not sure what you are trying to do, but I put up this one and also returns $data
| Code: |
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" |
which returned:
| Code: |
(Tcl) 1 % source regextest.tcl
x <tr bgcolor=#0099FF><td align=center><FONT SIZE='2' COLOR='#FFFFFF' face='verdana'>15&periuk=
(Tcl) 2 % |
|
|
| Back to top |
|
 |
walker Voice
Joined: 03 Sep 2009 Posts: 6
|
Posted: Thu Sep 03, 2009 2:11 am Post subject: |
|
|
thanks bro raider2k, i must explain what i want to do.
| Code: | set arg_date 15
regsub -nocase {.*<a\s+href=\"b.php\">$arg_date(.+)</b>.*} $data {\1} data
putquick "PRIVMSG $chan :$data" |
i want to show all text between <a href="b.php">15 to </b> with regsub command.
15 must inside variable arg_date.
please help. thank you so much |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Thu Sep 03, 2009 2:40 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
walker Voice
Joined: 03 Sep 2009 Posts: 6
|
Posted: Thu Sep 03, 2009 3:23 am Post subject: |
|
|
| 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. |
too much line bro.
i thik how to make <a\s+href=\"b.php\"> and $arg_date to be one
i want to be <a href="b.php">15 how it can be?
15 capture from set arg_date 15 as a value from varible arg_date |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Sep 03, 2009 4:23 am Post subject: |
|
|
The most likely issue here is that substitution of the variable named arg_date by its value using $arg_date will not occur because the braces that are surrounding the regsub pattern prevent normal variable, command and backslash substitution. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
walker Voice
Joined: 03 Sep 2009 Posts: 6
|
Posted: Thu Sep 03, 2009 4:28 am Post subject: |
|
|
| arfer wrote: | | The most likely issue here is that substitution of the variable named arg_date by its value using $arg_date will not occur because the braces that are surrounding the regsub pattern prevent normal variable, command and backslash substitution. |
so? it's imposibble to do that? please help |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Sep 03, 2009 4:45 am Post subject: |
|
|
It can be done by various means. Generally I choose the following method of including a variable within a regexp/regsub pattern
| Code: |
regexp -- [subst -nocommands -nobackslashes {pattern here}] "text here"
|
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.
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. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
walker Voice
Joined: 03 Sep 2009 Posts: 6
|
Posted: Thu Sep 03, 2009 4:51 am Post subject: |
|
|
| arfer wrote: | It can be done by various means. Generally I choose the following method of including a variable within a regexp/regsub pattern
| Code: |
regexp -- [subst -nocommands -nobackslashes {pattern here}] "text here"
|
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.
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. |
thanks bro. but 15 is a variable can be 13 or 31 or 30. depend on user request.
so, the script actually for grab user request like !date 15 15 used in regsub for search string in a html.
please help.....
do you have any yahoo messenger?[/b] |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Thu Sep 03, 2009 4:56 am Post subject: |
|
|
not sure if the following is what you are looking for, heres a try:
| Code: |
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" |
which returns
| Code: |
(Tcl) 20 % source regextest.tcl
<a href="b.php">15
(Tcl) 20 % |
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu Sep 03, 2009 5:16 pm Post subject: |
|
|
| walker wrote: | | Code: | | regsub -nocase {.*<a\s+href=\"b.php\">$arg_date(.+)</b>.*} $data {\1} data |
|
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. | Code: | set dynamic_regexp ".*<a\s+href=\"b.php\">$arg_date(.+)</b>.*"
regsub -nocase -- $dynamic_regexp $data {\1} data |
This is the preferred method of doing it. Use the interpreter to do the substitution for you when creating the variable. Make sure to remember the rules of double-substitution which I will explain. Any escape (\) which needs rendering should be triple (\\\) escaped instead. This means any used for formatting that aren't really a command. All others make sure to escape a single time. This includes special chars "{[\]}'$ among a few others. Using them in the regexp would be as easy as \\\\\\"\{\[ which would be substituted to \"{[ before being used within the regexp, just keep that in mind. Escapes are special cases and 5 must be used if the sequence is to be rendered after the substitutions. If it were simply {hello}[there] we wanted \{hello\}\[there\] would work and the escape upon the second substitution would be removed. Or, if we wanted the escapes rendered into the regular expression \\\{hello\\\}\\\[there\\\] would produce \{hello\}\[there\] . It's explained much better by others just google "+double substitution +tcl" or "+double evaluation +tcl" and read up, this is how you construct these types of regular expressions.
To me, using [subst] is a crutch of sorts, sure it works but it makes you look foolish and it certainly won't win any speed or beauty races. Using switches to confine [subst]'s natural behavior -nocommands -etc -etc is meant when there is no other alternative to things. Not as a way to "avoid the situation". It's more an avoiding learning more so I can find an easier way and more of the "just stick with what works" approach. Which don't get me wrong, is viable as well. Just not as much so as, possibly... simply using what eggdrop gives you, rather than force substitutions through additional commands. ya know what i mean?  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Sep 03, 2009 9:00 pm Post subject: |
|
|
Your solution will probably not work for two reasons :-
The \s will be substituted in setting the variable and come out as simply s, thus negating its real meaning in the regsub pattern (space character).
The text portion $arg_date(.+) may be interpreted as an array. Since arg_date is not an array, an error will occur.
Thats my reading of it anyway.
I don't think the command subst is foolish in the right circumstances, but like I said, each to his own. The main thing is choosing an option that works. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Sep 04, 2009 3:28 am Post subject: |
|
|
The \s issue can be avoided by adding an extra \ (i.e. \\s) and to avoid the array conflict use ${arg_date} instead. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Fri Sep 04, 2009 5:42 am Post subject: |
|
|
Yes, Sir_Fz, I agree. In fact I pretty much said as much in one of my earlier posts under this thread. Patterns need to be modified to account for them being defined outside braces. Possibly the quotes would need to be double backslashed too, though without testing I'm not certain of that. Even the < and > from html tags look a mite dubious, since these characters have meaning in tcl.
This is exactly why I long ago chose to use the command subst where suitable. I simply made too many silly mistakes in switching between patterns inside braces and patterns outside braces. This is rather more likely to make me look foolish than using an extra command. I can't see an extra few milliseconds execution time as generally being an issue. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Sep 04, 2009 8:35 pm Post subject: |
|
|
The objective here is to have a valid regexp pattern, even though < and > have a special meaning in Tcl they won't be interpreted as such since they're in a string (and not in an expression), a single escape for a quotation is sufficient to return and match it. Basically, there's no need to complicate things, perhaps by trial and error you'll finally reach the desired result (if things get difficult). _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|