AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hook name with dot and number (https://forums.alliedmods.net/showthread.php?t=164505)

Racoon 08-12-2011 12:13

Hook name with dot and number
 
Ok, I'd like to hook name which
a) contains a dot and number
For instance:
PHP Code:

.2 

or
PHP Code:

4. 

b) contains more than two dots
For instance:
PHP Code:

M.I.K.

Any ideas?

Exolent[jNr] 08-12-2011 12:17

Re: Hook name with dot and number
 
Use this regex pattern:

.*(\d\.|\.\d|\..*\.).*

Racoon 08-12-2011 12:51

Re: Hook name with dot and number
 
Quote:

Originally Posted by Exolent[jNr] (Post 1531062)
Use this regex pattern:

.*(\d\.|\.\d|\..*\.).*

Seems it works. As far as I understood you put both my requests in one code. What would the string look like only with a) request? Thanks in advance.

Exolent[jNr] 08-12-2011 13:20

Re: Hook name with dot and number
 
Remove the last switch option in the pattern.

.*(\d\.|\.\d).*

Racoon 08-12-2011 13:34

Re: Hook name with dot and number
 
Quote:

Originally Posted by Exolent[jNr] (Post 1531105)
Remove the last switch option in the pattern.

.*(\d\.|\.\d).*

Works perfectly! Thanks again.

Racoon 08-13-2011 13:58

Re: Hook name with dot and number
 
One more thing. Can you give a hint how to hook chat message, which contains more than 4 digits (that are not in a row) using regex?

Exolent[jNr] 08-13-2011 16:27

Re: Hook name with dot and number
 
I assume you don't know how to form regex patterns.

((^|\D)\d(?!\d))

Be sure to escape the ^ when you use it in the plugin.
You will need to also count your matches and check if they are 4 or more.

Racoon 08-14-2011 04:28

Re: Hook name with dot and number
 
Quote:

Originally Posted by Exolent[jNr] (Post 1531904)
I assume you don't know how to form regex patterns.

((^|\D)\d(?!\d))

Be sure to escape the ^ when you use it in the plugin.
You will need to also count your matches and check if they are 4 or more.

I've always had difficulties with regex regular expressions :D


All times are GMT -4. The time now is 03:26.

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