This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

filter text with regexp

Help for those learning Tcl or writing their own scripts.
Post Reply
j
johne
Voice
Posts: 29
Joined: Tue Jul 19, 2005 2:24 am

filter text with regexp

Post by johne »

i need to add a regexp to this to filter out the text file and only output lines that begin with the number 3...and im really at a loss at how to integrate that in with my current script.

Code: Select all

proc text {n u h c t} {
   set x [::http::geturl http://www.website.com/example.txt]
   foreach e [split [::http::data $x] \n] {puthelp "privmsg $c :$e"}
   ::http::cleanup $x
}
any help would be greatly appreciated.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You don't really need regexp for that, check the string manual, and place that before the "puthelp "privmsg $c :$e"" line in a if statement.
Once the game is over, the king and the pawn go back in the same box.
j
johne
Voice
Posts: 29
Joined: Tue Jul 19, 2005 2:24 am

Post by johne »

ok, ill start looking into that, but from reading in the forums, if i want to parse html, im going to need to use regexp anyways correct?
j
johne
Voice
Posts: 29
Joined: Tue Jul 19, 2005 2:24 am

Post by johne »

the lines that im wanting to strip out of the text file look like this

Code: Select all

 3<left>501 NEW JERSEY      <right> 96<br><left>502 ORLANDO         <right> 85<br><center><h>      FINAL</h><br><br>
 3<left>503 LA CLIPPERS     <right> 75<br><left>504 INDIANA         <right> 97<br><center><h>      FINAL</h><br><br>
 3<left>505 GOLDEN STATE    <right>100<br><left>506 PHILADELPHIA    <right>111<br><center><h>      FINAL</h><br><br>
 3<left>507 SAN ANTONIO     <right>107<br><left>508 NEW YORK        <right> 96<br><center><h>      FINAL</h><br><br>
 3<left>509 UTAH            <right> 89<br><left>510 BOSTON          <right>101<br><center><h>      FINAL</h><br><br>
 3<left>511 NEW ORLEANS     <right> 69<br><left>512 MINNESOTA       <right> 88<br><center><h>      FINAL</h><br><br>
 3<left>513 PORTLAND        <right> 79<br><left>514 MEMPHIS         <right> 89<br><center><h>      FINAL</h><br><br>
 3<left>515 TORONTO         <right> 80<br><left>516 HOUSTON         <right> 67<br><center><h>08:25 4th Q</h><br><br>
 3<left>517 WASHINGTON      <right> 74<br><left>518 DENVER          <right> 70<br><center><h>04:17 3rd Q</h><br><br>
j
johne
Voice
Posts: 29
Joined: Tue Jul 19, 2005 2:24 am

Post by johne »

im not sure if im going in the right direction with this, but ive managed to code something that gives me 0 output, but no errors.

Code: Select all

   foreach e [split [::http::data $x] \n] {
     if {[regexp {^3} $e] == 1} {
       puthelp "privmsg $c :$e"
j
johne
Voice
Posts: 29
Joined: Tue Jul 19, 2005 2:24 am

Post by johne »

ok now that that works (there was a space at the beginning of the text line that was giving me problems)...it only outputs the lines of text that are defined by the regexp

Code: Select all

if {[regexp {^\x020[3]} $e] == 1} {
now i need to work on getting the format correct

id like to take this:

Code: Select all

3<left>501 NEW JERSEY      <right> 96<br><left>502 ORLANDO         <right> 85<br><center><h>      FINAL</h><br><br>
and end up with this

Code: Select all

NEW JERSEY 96 ORLANDO 85 FINAL
im pretty sure this is way over my head now, so feel free to help out :D
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

regsub -all -- {^3|<(/?)[A-z]{1,}>} $string "" string
# remove the extra spaces
set string [join $string]
Post Reply