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.

regexp - Help please

Help for those learning Tcl or writing their own scripts.
Post Reply
W
Wannabe
Voice
Posts: 17
Joined: Fri Feb 10, 2006 1:02 pm

regexp - Help please

Post by Wannabe »

Hey guys, im having problems with my regexp, it should technically work, but it refuses to, so ill give you what i have and see if anyone can spot my mistake/s for me :D

Cheers

Current code : regexp -nocase -- {\[hostname\] => .+} $html hostname

Code im trying to parse

Code: Select all

 
    <pre>Array
(
    [nsserver] => Array
        (
            [address] => 194.154.191.10:27015
            [hostname] => Wireplay UK NS [Classictastic][NS + FF on]
            [map] => ns_caged
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 2
            [max_players] => 16
            [protocol] => 47
            [server_type] => d
            [server_os] => l
            [password] => 0
            [mod] => 1
            [mod_info] => http://www.unknownworlds.com/ns/
            [mod_download] => http://www.unknownworlds.com/ns/view?action=files
            [mod_version] => 0
            [mod_size] => -709672960
            [mod_ssonly] => 9
            [mod_customdll] => 0
        )

)
</pre>
[/code]
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

If you're trying to capture the hostname, you need something like:

regexp -nocase -- {\[hostname\] \=\> (.*?)\n} $html fullmatchvar hostname

You need to escape the = and >, you need to use () around the portion you want to capture into a var, and you need to use a "fullmatchvar" and "specific-match-var" (eg, hostname).. I assumed you wanted the entire string after => and so I used a newline \n to delimit the end point.

Check the manpage for re_syntax and regexp that comes with tcl for more details.
Post Reply