| View previous topic :: View next topic |
| Author |
Message |
Wannabe Voice
Joined: 10 Feb 2006 Posts: 17
|
Posted: Mon Jul 09, 2007 9:32 am Post subject: regexp - Help please |
|
|
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
Cheers
Current code : regexp -nocase -- {\[hostname\] => .+} $html hostname
Code im trying to parse
| Code: |
<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] |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Mon Jul 09, 2007 1:30 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
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
|
|