Raised This Month: $ Target: $400
 0% 

Regex Patterns


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-21-2009 , 19:06   Regex Patterns
Reply With Quote #1

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$
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 02-21-2009 , 19:18   Re: Regex Patterns
Reply With Quote #2

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.
__________________

Last edited by stupok; 02-21-2009 at 19:21.
stupok is offline
Old 02-21-2009, 19:29
joaquimandrade
This message has been deleted by joaquimandrade. Reason: Loss of time
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-21-2009 , 19:45   Re: Regex Patterns
Reply With Quote #3

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
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-21-2009 , 19:47   Re: Regex Patterns
Reply With Quote #4

@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.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-21-2009 at 20:14.
Exolent[jNr] is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 02-21-2009 , 21:26   Re: Regex Patterns
Reply With Quote #5

@arkshine
What is ?i: ?
__________________
stupok is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 02-21-2009 , 21:38   Re: Regex Patterns
Reply With Quote #6

Quote:
Originally Posted by stupok View Post
@arkshine
What is ?i: ?
Case insensitive group I think.
__________________

Community / No support through PM
danielkza is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 02-21-2009 , 21:39   Re: Regex Patterns
Reply With Quote #7

?i works? what the hell!
BOYSplayCS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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