Regular Expression, Or Something More?

coldfusion244

Well-known member
Joined
Nov 24, 2004
Messages
266
Location
Philadelphia
I have the source to a webpage, in the webpage contains information about what players are in our game server, as well as their IPs. I am making a tool to get this information and somehow extract it from this source then display it.

Im not sure if 1 regular expression or a combination of them will work, im very new to Regex. So any help is appreciated. If Regex wont do, maybe some hints in the right direction toawrds parsing it out :)

Thanks guys
 

Attachments

Question

coldfusion244 said:
I have the source to a webpage, in the webpage contains information about what players are in our game server, as well as their IPs. I am making a tool to get this information and somehow extract it from this source then display it.

Im not sure if 1 regular expression or a combination of them will work, im very new to Regex. So any help is appreciated. If Regex wont do, maybe some hints in the right direction toawrds parsing it out :)

Thanks guys

In your text file I find (amongst others) the following two lines:
Code:
<tr><td>Web Key</td><td><input type=password name=webkey maxlength=32 size=35 value="F1414F141F1414F1414F1414F1414321"></td></tr>

<tr bgcolor=#808080><td><input type=submit value="Slot 01" name=1slot></td><td><font color=#FFFFFF>NullReference</font></td><td>69.139.11.62:2921</td><td>UPDT</td><td>0.0</td><td>1</td><td><tr bgcolor=#0000FF><td></td><td>1 Player</td><td></td><td></td><td></td><td></td><td></td></tr>

Do these two lines represent the ones with the IP and username?

Also, will the IP address always have a port (that is, ip colon port)?

Thanks. :)
 
I kinda figured it out the long drawn out way.

Yes richard, I want the playername, which then is followed by the IP and always has the port number.

I used a regex to split the font color which is exactly the save before every name, then i looped until i found the end of the font, did some subtraction and substringed the player name out.

To get the IP (I dont care about getting the port) i then used string.split to split the already split regex strings and got my IP that way. I didnt notice before how much repition there was that I could go by.

I much easier approach with a normal Regex string would be appreciated ;)
 
This is one way

coldfusion244 said:
I kinda figured it out the long drawn out way.

Yes richard, I want the playername, which then is followed by the IP and always has the port number.

I used a regex to split the font color which is exactly the save before every name, then i looped until i found the end of the font, did some subtraction and substringed the player name out.

To get the IP (I dont care about getting the port) i then used string.split to split the already split regex strings and got my IP that way. I didnt notice before how much repition there was that I could go by.

I much easier approach with a normal Regex string would be appreciated ;)


Given the code from last post:
Code:
<tr><td>Web Key</td><td><input type=password name=webkey maxlength=32 size=35 value="F1414F141F1414F1414F1414F1414321"></td></tr>

<tr bgcolor=#808080><td><input type=submit value="Slot 01" name=1slot></td><td><font color=#FFFFFF>NullReference</font></td><td>69.139.11.62:2921</td><td>UPDT</td><td>0.0</td><td>1</td><td><tr bgcolor=#0000FF><td></td><td>1 Player</td><td></td><td></td><td></td><td></td><td></td></tr>

One thing you could do is use the following search strings:

name\=(.+)\s

The above search string will return the name ("webkey" in this case) as group 1, which is represented by the first, and only, set of parentheses. It says "find name followed by an equal sign followed by any characters followed by a white-space character".

[^0-9]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+):([0-9]+)[^0-9]

The above search string will return the ip address in group 1 and the port number in group 2, which are represented by the first and second group of parentheses. In the above code it would return "69.139.11.62" and "2921". It says "find a non-numeric character followed by 4 instances of (one or more numbers followed by a period) followed by a colon followed by one or more numbers followed by a non-numeric character".

Now...there are different ways to do this. If:

* your file has more than one user/ip entry and
* your file is broken into lines (delineated by newlines) and
* the pattern is always user then ip then user then ip...

Then:

You can just alternately call each of the above search strings and obtain each user and ip as you go. You will have to keep track of where you are in the data stream so that you dont start at the beginning each time and get the same search result over and over. I am guessing that the above starting point will get you going in the direction you need.

Just smack me for more or better info. :)
 
Richard,

The way you put it did the trick. My problem was I wasnt checking for a non-numeric character before the IPs. :o Sometimes I wonder if parts of my brain shut down.

Thank you very much!
 
Back
Top