egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

filter text with regexp

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Thu Dec 22, 2005 1:23 am    Post subject: filter text with regexp Reply with quote

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:

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Dec 22, 2005 2:11 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Thu Dec 22, 2005 2:13 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Thu Dec 22, 2005 2:19 am    Post subject: Reply with quote

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

Code:

 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>
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Thu Dec 22, 2005 3:58 am    Post subject: Reply with quote

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:

   foreach e [split [::http::data $x] \n] {
     if {[regexp {^3} $e] == 1} {
       puthelp "privmsg $c :$e"
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Thu Dec 22, 2005 6:42 am    Post subject: Reply with quote

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:

if {[regexp {^\x020[3]} $e] == 1} {


now i need to work on getting the format correct

id like to take this:

Code:

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:

NEW JERSEY 96 ORLANDO 85 FINAL


im pretty sure this is way over my head now, so feel free to help out Very Happy
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Dec 22, 2005 1:07 pm    Post subject: Reply with quote

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

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber