Jump to content

How to extract names and ip addresses from my string?


Recommended Posts

How to extract all Name-IP pares in array from following string. I think it can be done with RegExp but I can't understand how :)

NOTE: Foll text is a single string which I get from UDP packet.

String:

hostname:  Counter-Strike 1.6
version :  47/1.1.2.5 3647 insecure 
tcp/ip  :  192.168.1.0:27015
map  :  de_inferno at: 0 x, 0 y, 0 z
players :  24 active (26 max)

#     name userid uniqueid frag time ping loss adr
# 1 "player1" 1604 VALVE_ID_LAN   4 15:28   27  0 192.168.1.1:2319
# 2 "player2" 1452 VALVE_ID_LAN   7  1:19:58   13   0 192.168.1.2:27005
# 3 "player3" 1518 VALVE_ID_LAN   7 52:38   27  0 192.168.1.3:63469
# 4 "player4" 1635 VALVE_ID_LAN   4 03:50   29  0 192.168.1.4:27005
# 5 "player5" 1611 VALVE_ID_LAN  16 11:13   28  0 192.168.1.5:27005
# 6 "player6" 1601 VALVE_ID_LAN   9 18:57   20  0 192.168.1.6:27005
# 7 "player7" 1617 VALVE_ID_LAN   7 10:04   36  0 192.168.1.7:27005
# 8 "player8" 1626 VALVE_ID_LAN   2 07:59   29  0 192.168.1.8:27005
# 9 "player9" 1504 VALVE_ID_LAN   4 58:42   33  1 192.168.1.9:27005
...

Example:

a[0] = ' "player1" 192.168.1.1 '
a[1] = ' "player2" 192.168.1.2 '
...
Edited by qwer85
Link to comment
Share on other sites

Hi,

#include<Array.au3>
Global $text = FileRead(FileOpen(@ScriptDir & '\text.txt', 0))
Global $players =  StringRegExp($text, '(?<=")\w+', 3)
Global $ips =  StringRegExp($text, '(?<=\d )\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?=:)', 3)
_ArrayDisplay($players)
_ArrayDisplay($ips)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I have 1 problem... Player name can include other symbols including numbers (exept symbol ")

Can you change this function StringRegExp($text, '(?<=")\w+', 3) to read from symbol " until it meet next symbol " ?

Ex: Name = "$up3r.Play3r#1"

[EDIT]

I've done it myself by writing as following:

StringRegExp($text, '(?<=").+(?=")', 3)

[/EDIT]

Edited by qwer85
Link to comment
Share on other sites

Hi,

you can also use this pattern: (?<=").+?(?=")|(?<=\d )\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?=:)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

I have 1 problem... Player name can include other symbols including numbers (exept symbol ")

Can you change this function StringRegExp($text, '(?<=")\w+', 3) to read from symbol " until it meet next symbol " ?

Ex: Name = "$up3r.Play3r#1"

[EDIT]

I've done it myself by writing as following:

StringRegExp($text, '(?<=").+(?=")', 3)

[/EDIT]

StringRegExp($text, '"(.*?)"', 3)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi Ron,

there is a difference. Your version includes the " mine doesn't! I guess, mine is what he was looking for.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Hi Ron,

there is a difference. Your version includes the " mine doesn't! I guess, mine is what he was looking for.

So long,

Mega

Um... no... only what is in the parenthesis is captured, and the quotes are outside of it :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Um... no... only what is in the parenthesis is captured, and the quotes are outside of it :)

Hi,

u yes, sorry! I'm used to use lookahead and lookbehind. Is that slower or bad style?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Hi,

u yes, sorry! I'm used to use lookahead and lookbehind. Is that slower or bad style?

So long,

Mega

The only time you need to over work the engine (In this case it's a "simple" search) is when you are going to be extracting difficult data to get. That's really the only time that back and forward make a difference, not when you're trying to grab the data in one string chunk.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...