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.

Extract Words

Help for those learning Tcl or writing their own scripts.
Post Reply
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Extract Words

Post by Access »

Code: Select all

            <td align="right">Saudi-Arabien</td>
            <td></td>
            <td>Spanien</td>
          </tr>
          <tr class="ergebnis">
            <td align="right">0</td>

            <td>:</td>
            <td>0</td>
          </tr>
        </table>
      </div>

      
Thats Data i´ve cached from a Webpage....

Now i am to stupid to use regexp i think....

I want the following variables:

$team1 = "Saudi-Arabien"
$team2 = "Spanien"
$score1 = "0"
$score2 = "0"

HOW CAN I DO THIS? Plz help :(

THX!
G
Garp
Voice
Posts: 29
Joined: Mon Sep 15, 2003 7:58 pm

Post by Garp »

p
phab
Voice
Posts: 12
Joined: Mon Aug 22, 2005 6:34 am

Post by phab »

Quick and REALLY dirty:

Code: Select all

#!/usr/bin/env tclsh
set output {            <td align="right">Saudi-Arabien</td>
            <td></td>
            <td>Spanien</td>
          </tr>
          <tr class="ergebnis">
            <td align="right">0</td>

            <td>:</td>
            <td>0</td>
          </tr>
        </table>
      </div>}

regsub -all -- {<[^>]*>} $output "" output 
regsub -all -- {\n} $output "" output

puts "[lindex $output 0] [lindex $output 2]:[lindex $output 4] [lindex $output 1]"
Output:

Code: Select all

phab@Debian:~$ ./blahblah.tcl
Saudi-Arabien 0:0 Spanien
Post Reply