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 

Regexp help

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


Joined: 10 Feb 2006
Posts: 17

PostPosted: Sat Aug 04, 2007 2:56 pm    Post subject: Regexp help Reply with quote

Hey guys, im struggling with a script im trying to write, i have a php script which dumps an array into a browser, and a tcl script that parses several bits of information from that array dump.

However, i now have several sections which are identical appart from the stored information im trying to retrieve, and im not sure how to get all matching results, anyone able to explain a method?

What im wanting is the information behind [hostname] and [map] from each section, the array dump is :

Code:

    Array
(
    [nsserver] => Array
        (
            [address] => 194.154.191.10:27015
            [hostname] => Wireplay UK NS [Classictastic][NS + FF on]
            [map] => ns_mineshaft
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 4
            [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
        )

    [nsserver2] => Array
        (
            [address] => 194.154.191.11:27015
            [hostname] => Wireplay UK NS [Fight Club][CO + Extralevels]
            [map] => co_daimos_beta5
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 0
            [max_players] => 18
            [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
        )

    [nsserver3] => Array
        (
            [address] => 194.154.191.12:27015
            [hostname] => Wireplay UK NS [Melting Pot][CO only]
            [map] => co_angst
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 2
            [max_players] => 18
            [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
        )

    [nsserver4] => Array
        (
            [address] => 194.154.191.13:27015
            [hostname] => Wireplay UK NS [Vets Surgery][NS + FF on]
            [map] => ns_mineshaft
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 2
            [max_players] => 18
            [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
        )

    [nsserver5] => Array
        (
            [address] => 194.154.191.14:27015
            [hostname] => Wireplay UK NS [ProtoLab][CO + PLUGINS]
            [map] => co_core
            [gamedir] => ns
            [gamename] => NS v3.2.0
            [num_players] => 3
            [max_players] => 18
            [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
        )

)
   
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Aug 04, 2007 10:34 pm    Post subject: Reply with quote

Something like:

Code:

set myvar [regexp -all -inline {\[hostname\] (.*?)\n\[map\] (.*?)\n} $input]

That's one way to get the data into a var, then you can use foreach or whatever you want to manipulate it. You'll prolly have to clean the data up first tho, with regsub or somn..
Back to top
View user's profile Send private message
Wannabe
Voice


Joined: 10 Feb 2006
Posts: 17

PostPosted: Sun Aug 05, 2007 5:53 am    Post subject: Reply with quote

What i need ideally, is to read the php array into a tcl array, if i can do that, it would be perfect, only im stuggling to think of a way that isnt far beyond my tcl skills.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Aug 05, 2007 12:06 pm    Post subject: Reply with quote

Once the data is in a var, you can do whatever you want with it, including putting it into an array.

Code:

array set hostnames [regexp -inline -all {\[hostname\] (.*?)\n} $input]
array set map [regexp -all -inline {\[map\] (.*?)\n} $input]

or

array set data [regexp -all -inline {\[hostname\] (.*?)\n\[map\] (.*?)\n} $input]

or

set count 0;set var1 "";set var2 ""
foreach line {$input} {
        if {[regexp {\[hostname\] (.*?)\n\[map\] (.*?)\n} $line fullmatch var1 var2]} {
                  incr count
                  array set myvar "$var1 $var2" "$count"
         }
}

I use something similar to the last example in a quotes script, to count up the total lines and to pull individual matches (hence using the $count var to keep stuffing data into the array and have a running total at the same time.)
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Sun Aug 05, 2007 8:29 pm    Post subject: Reply with quote

Note: You do not need to specify the -inline switch with -all. The -all switch already gives the number of possible matches.
_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
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