AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Regex separating port from IP (https://forums.alliedmods.net/showthread.php?t=118176)

z3rongod 02-08-2010 10:57

Regex separating port from IP
 
Hello! I am trying to find a way to separate the port from IP using regex, but i have no clue how to achieve this. Wish there was a similar function as PHP's explode() :-)

new serverip[25]
new serverport[6]
get_user_ip(99, serverip, 25, 0)
...

Arkshine 02-08-2010 11:02

Re: Regex separating port from IP
 
Using get_user_ip(), to get the ip without port, replace 0 by 1.

You can retrieve the "ip" as a server cvar the same for "port".

You don't need regex.

Edit : Or like said Yami, you can break using for example strtok().

z3rongod 02-08-2010 11:28

Re: Regex separating port from IP
 
separate PORT from ip. I am trying to get the server's port and store it in a string.

YamiKaitou 02-08-2010 11:32

Re: Regex separating port from IP
 
Break the string at ':' and you will have the IP and Port.

z3rongod 02-08-2010 11:48

Re: Regex separating port from IP
 
So there is a function similar to PHP's explode()

Could you please point it out for me?

YamiKaitou 02-08-2010 11:51

Re: Regex separating port from IP
 
Have you even looked for yourself yet?

http://amxmodx.org/funcwiki.php?go=func&id=872
http://amxmodx.org/funcwiki.php?go=func&id=860

z3rongod 02-08-2010 12:22

Re: Regex separating port from IP
 
Thank you

Bugsy 02-08-2010 12:48

Re: Regex separating port from IP
 
untested
PHP Code:

new szIPPort25 ];
new 
szPort];

get_user_ipid szIPPort charsmaxszIPPort ) );

new 
iPos strfindszIPPort ":" );

if ( 
iPos != -)
{
     
//Copy port to szPort string 
     
copyszPort charsmaxszPort ) , szIPPortPos ] );

     
//This will make szIPPort hold only the IP 
     
szIPPortiPos ] = EOS;



Arkshine 02-08-2010 13:18

Re: Regex separating port from IP
 
More easier to use strtok() :

PHP Code:

new ip  25 ]; 
new 
port]; 
    
get_user_ipid ip charsmaxip ) ); 
strtokipipcharsmaxip ), portcharsmaxport ), ':' ); 


Spunky 02-08-2010 13:59

Re: Regex separating port from IP
 
IP addresses are only 15 characters Arkshine.

PHP Code:

new ip[16]
new 
port[6]

get_user_ip(idip15)
strtok(ipip15port5':'

Calling charsmax() is wasteful as well. You already know the size.


All times are GMT -4. The time now is 07:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.