SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 12/04/2011, 08:41 AM   #21
Fro1sha
Big Clucker
 
Fro1sha's Avatar
 
Join Date: Nov 2009
Posts: 168
Reputation: 32
Default Re: Regular expression

Speed test:
pawn Code:
main()
{      
    new
        i,
        tick
    ;
   
    const
        loop = 100000
    ;
   
    tick = tickcount();
    while ( i != loop )
    {
        regex_match("[email protected]", "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
        i++;
    }
    printf("1) Time: %d", tickcount() - tick);
   
    new
        RegEx:rEmail
    ;
   
    rEmail = regex_build("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
    i = 0;
    tick = tickcount();
    while ( i != loop )
    {
        regex_match_exid("[email protected]", rEmail);
        i++;
    }
    printf("2) Time: %d", tickcount() - tick);

}
Result:
Quote:
1) Time: 11252
2) Time: 308
-----------------
1) Time: 11249
2) Time: 300
__________________
[Plugin] MultiThread
[Plugin] GMT Timezone
[Plugin] Regular expression

Development any plugins, for the money.
Разработка любых плагинов за деньги.
Fro1sha is offline   Reply With Quote
Old 12/04/2011, 11:21 AM   #22
Alby Fire
Big Clucker
 
Join Date: Dec 2010
Posts: 125
Reputation: 2
Default Re: Regular expression

Genius... thank you
Alby Fire is offline   Reply With Quote
Old 12/04/2011, 11:41 AM   #23
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,996
Reputation: 3154
Default Re: Regular expression

Quote:
Originally Posted by Fro1sha View Post
Quote:
1) Time: 11252
2) Time: 308
-----------------
1) Time: 11249
2) Time: 300
I misread those results at first as it wasn't initially clear to me that it was two runs of the same experiment so I thought that the two versions were basically the same. However now that I've seen what it is really they are some VERY impressive results! I didn't expect them to be THAT different. Very nice work Fro1sha!
Y_Less is offline   Reply With Quote
Old 12/04/2011, 01:12 PM   #24
Falcon.
High-roller
 
Falcon.'s Avatar
 
Join Date: Jul 2010
Location: Brasнlia - DF
Posts: 1,748
Reputation: 173
Default Re: Regular expression

Excellent work.
It's pretty good.

Congratulations
__________________

Republic Adventure RPG
em breve...

Falcon. is offline   Reply With Quote
Old 12/04/2011, 01:44 PM   #25
Steamator
Little Clucker
 
Steamator's Avatar
 
Join Date: Dec 2010
Posts: 38
Reputation: 0
Default Re: Regular expression

How can i compare if 2 strings are same?
[ABC]Player == [ABC]Player ?
__________________
Steamator is offline   Reply With Quote
Old 12/04/2011, 02:17 PM   #26
JaTochNietDan
High-roller
 
JaTochNietDan's Avatar
 
Join Date: Apr 2007
Location: Republic of Ireland
Posts: 4,215
Reputation: 363
Default Re: Regular expression

Quote:
Originally Posted by Steamator View Post
How can i compare if 2 strings are same?
[ABC]Player == [ABC]Player ?
That is better done with strcmp, not regular expressions.
__________________
Releases:
[Includes]: [jBan] | [jBanLite]
[Plugins]: [FileManager] | [Execute]
[Applications]: [Remote Administrator *NEW] | [Script King] | [RCON GUI]
JaTochNietDan is offline   Reply With Quote
Old 12/04/2011, 02:45 PM   #27
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,996
Reputation: 3154
Default Re: Regular expression

You can't really do it with regular expressions at all...
Y_Less is offline   Reply With Quote
Old 13/04/2011, 02:59 AM   #28
lpiob
Little Clucker
 
Join Date: Aug 2010
Posts: 6
Reputation: 0
Default Re: Regular expression

I love you.
lpiob is offline   Reply With Quote
Old 13/04/2011, 11:02 PM   #29
JaTochNietDan
High-roller
 
JaTochNietDan's Avatar
 
Join Date: Apr 2007
Location: Republic of Ireland
Posts: 4,215
Reputation: 363
Default Re: Regular expression

I'm not particularly knowledgeable of regular expressions yet, but I guess another use could be using it to find out if someone is trying to advertise a server by detecting an IP address in their input? I whipped this expression up, seems to work when I tested it, not sure if it's very effecient though, certainly doesn't look it. Also it doesn't check if the IP itself is valid, it only looks for the IP format in the string.

pawn Code:
#define ContainsIP(%1) \
    regex_match(%1, "(.*?)([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})(.*?)")

Usage:

pawn Code:
public OnPlayerText(playerid, text[])
{
    if(ContainsIP(text)) return SendClientMessage(playerid, red ,"Please don't advertise on our server");
    return 1;
}

Just a thought.
__________________
Releases:
[Includes]: [jBan] | [jBanLite]
[Plugins]: [FileManager] | [Execute]
[Applications]: [Remote Administrator *NEW] | [Script King] | [RCON GUI]
JaTochNietDan is offline   Reply With Quote
Old 14/04/2011, 09:41 AM   #30
Fro1sha
Big Clucker
 
Fro1sha's Avatar
 
Join Date: Nov 2009
Posts: 168
Reputation: 32
Default Re: Regular expression

Quote:
Originally Posted by JaTochNietDan View Post
I'm not particularly knowledgeable of regular expressions yet, but I guess another use could be using it to find out if someone is trying to advertise a server by detecting an IP address in their input? I whipped this expression up, seems to work when I tested it, not sure if it's very effecient though, certainly doesn't look it. Also it doesn't check if the IP itself is valid, it only looks for the IP format in the string.

pawn Code:
#define ContainsIP(%1) \
    regex_match(%1, "(.*?)([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})(.*?)")

Usage:

pawn Code:
public OnPlayerText(playerid, text[])
{
    if(ContainsIP(text)) return SendClientMessage(playerid, red ,"Please don't advertise on our server");
    return 1;
}

Just a thought.
This version faster =)
pawn Code:
stock ContainsIPEx(const string[])
{
    static
        RegEx:rCIP
    ;
   
    if ( !rCIP )
    {      
        rCIP = regex_build("(.*?)([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})(.*?)");
    }
   
    return regex_match_exid(string, rCIP);
}
__________________
[Plugin] MultiThread
[Plugin] GMT Timezone
[Plugin] Regular expression

Development any plugins, for the money.
Разработка любых плагинов за деньги.
Fro1sha is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Map] Las Venturas Regular Day Flyfishes Maps 17 16/05/2011 05:53 PM
Skins and regular players Anthonyx3' Help Archive 12 08/08/2010 01:40 AM
Regular Players Club help! bpeterson Help Archive 12 26/02/2009 07:53 PM
Regular San Andreas? Jakalak General 8 01/01/2009 07:04 PM


All times are GMT. The time now is 06:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.