AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Regex Patterns (https://forums.alliedmods.net/showthread.php?t=86165)

Exolent[jNr] 02-21-2009 19:06

Regex Patterns
 
I'm trying to learn Regex patterns because I have seen them to be more useful than trying to make a function to check.

Let's say I wanted to check if the given string was a SteamID.
Would this work:
^STEAM_0:(0|1):\d$

stupok 02-21-2009 19:18

Re: Regex Patterns
 
It would not work, because you're only allowing for one digit after the second colon.

Something like this, maybe: ^STEAM_0:(?:0|1):\d{1,16}$

I'm not sure what the maximum length of the number after the second colon may be. I added "?:" so it won't save the number after the first colon.

Arkshine 02-21-2009 19:45

Re: Regex Patterns
 
What about :

(?i:STEAM)_0:(0|1):\d+ -> case insensitive + infinite number + check if contained into the string

or

^(?i:STEAM)_0:(0|1):\d+$ -> case insensitive + infinite number + the string must be exact

Exolent[jNr] 02-21-2009 19:47

Re: Regex Patterns
 
@stupok
I guess I misunderstood \d because I thought it meant that it could be any number of digits, not just 1.

@joaquimandrade
However, that program is not free, and I do not find it necessary to buy.

@arkshine
Thanks!


EDIT:

When I use this:
^STEAM_0:(0|1):\d+$

And I test with:
STEAM_0:1:2345

I get these matches:
STEAM_0:1:2345
1

Is that normal?


EDIT 2:
Nevermind. I did some testing and it always returns that, even with a plugin I made to test.

stupok 02-21-2009 21:26

Re: Regex Patterns
 
@arkshine
What is ?i: ?

danielkza 02-21-2009 21:38

Re: Regex Patterns
 
Quote:

Originally Posted by stupok (Post 766317)
@arkshine
What is ?i: ?

Case insensitive group I think.

BOYSplayCS 02-21-2009 21:39

Re: Regex Patterns
 
?i works? what the hell!


All times are GMT -4. The time now is 16:53.

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