| View previous topic :: View next topic |
| Author |
Message |
johne Voice
Joined: 19 Jul 2005 Posts: 29
|
Posted: Thu Dec 22, 2005 1:23 am Post subject: filter text with regexp |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Dec 22, 2005 2:11 am Post subject: |
|
|
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 |
|
 |
johne Voice
Joined: 19 Jul 2005 Posts: 29
|
Posted: Thu Dec 22, 2005 2:13 am Post subject: |
|
|
| 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 |
|
 |
johne Voice
Joined: 19 Jul 2005 Posts: 29
|
Posted: Thu Dec 22, 2005 2:19 am Post subject: |
|
|
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 |
|
 |
johne Voice
Joined: 19 Jul 2005 Posts: 29
|
Posted: Thu Dec 22, 2005 3:58 am Post subject: |
|
|
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 |
|
 |
johne Voice
Joined: 19 Jul 2005 Posts: 29
|
Posted: Thu Dec 22, 2005 6:42 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Thu Dec 22, 2005 1:07 pm Post subject: |
|
|
| 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 |
|
 |
|