SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 11/04/2011, 08:42 AM   #1
Fro1sha
Big Clucker
 
Fro1sha's Avatar
 
Join Date: Nov 2009
Posts: 168
Reputation: 22
Default Regular expression 0.2

Description:
Wiki
boost

Natives:
pawn Code:
native RegEx:regex_build(const expression[]);
native regex_delete(RegEx:expID);
native regex_isvalid(RegEx:expID);
native regex_delete_all();

native regex_match(const string[], const expression[]);
native regex_search(const string[], const expression[]);
native regex_replace(const string[], const expression[], const to[], dest[], size = sizeof dest);

native regex_match_exid(const string[], RegEx:expID);
native regex_search_exid(const string[], RegEx:expID);
native regex_replace_exid(const string[], RegEx:expID, const to[], dest[], size = sizeof dest);

Examples:
pawn Code:
#define IsValidEmail(%1) \
    regex_match(%1, "[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}")
   
#define IsValidRpName(%1) \
    regex_match(%1, "([A-Z]{1,1})[a-z]{2,9}+_([A-Z]{1,1})[a-z]{2,9}")
   
#define IsValidText(%1) \
    regex_match(%1, "[ а-яА-Яa-zA-Z0-9_,!\\.\\?\\-\\+\\(\\)]+")

stock IsValidRpNameEx(const string[])
{
    static
        RegEx:rRpName
    ;
   
    if ( !rRpName )
    {      
        rRpName = regex_build("([A-Z]{1,1})[a-z]{2,9}+_([A-Z]{1,1})[a-z]{2,9}");
    }
   
    return regex_match_exid(string, rRpName);
}

stock IsValidTextEx(const string[])
{
    static
        RegEx:rText
    ;
   
    if ( !rText )
    {      
        rText = regex_build("[ а-яА-Яa-zA-Z0-9_,!\\.\\?\\-\\+\\(\\)]+");
    }
   
    return regex_match_exid(string, rText);
}
pawn Code:
stock IsValidEmailEx(const string[])
{
    static
        RegEx:rEmail
    ;
   
    if ( !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])?");
    }
   
    return regex_match_exid(string, rEmail);
}

main()
{      
    printf("ValidEmail: %s", IsValidEmailEx("test@test.test") ? ("true") : ("false"));
    printf("Non ValidEmail: %s", !IsValidEmailEx("t[e]st@test.test") ? ("true") : ("false"));
}

Log:
  • 0.2.1
    - Fix params in (regex_delete, regex_isvalid)
  • 0.2
    - Added new natives
    pawn Code:
    native RegEx:regex_build(const expression[]);
    native regex_delete(RegEx:expID);
    native regex_isvalid(RegEx:expID);
    native regex_delete_all();

    native regex_match_exid(const string[], RegEx:expID);
    native regex_search_exid(const string[], RegEx:expID);
    native regex_replace_exid(const string[], RegEx:expID, const to[], dest[], size = sizeof dest);
  • 0.1
    - First release

Download:
__________________
[Plugin] MultiThread
[Plugin] GMT Timezone
[Plugin] Regular expression

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

Last edited by Fro1sha; 15/04/2011 at 04:39 AM.
Fro1sha is offline   Reply With Quote
Old 11/04/2011, 08:54 AM   #2
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,082
Reputation: 2512
Default Re: Regular expression

Ahh, I was wondering if anyone would ever do this - it has been something I've wanted for a while but never enough to actually get around to producing. Excellent work. One question, could you add pre-compilation for speed, example:

pawn Code:
new RegEx:rRPName = regex_build("([A-Z]{1,1})[a-z]{2,9}+_([A-Z]{1,1})[a-z]{2,9}");

regex_match_compile(name0, rRPName);
regex_match_compile(name1, rRPName);
regex_match_compile(name2, rRPName);

Also, that example doesn't actually check for valid emails:

http://haacked.com/archive/2007/08/2...s-until-i.aspx
Y_Less is offline   Reply With Quote
Old 11/04/2011, 09:03 AM   #3
Calgon
Godfather
 
Join Date: Jan 2009
Posts: 6,210
Reputation: 835
Default Re: Regular expression

Thank you. SO MUCH!

I've been waiting for something like this forever, I've been having to create complex (well, I say complex, in comparison to regex, but functions generally containing a billion unnecessary checks in comparison to one regex statement).

Do you mind if I mirror the download?

Mirror: http://www.fwright.com/files/regex.zip (only includes include & plugin .so + .dll).
__________________
If you don't know then Don't post here.

Quote:
(10:27:18 PM) dugi: hello is this the police?
(10:27:25 PM) dugi: Calgon is being mean
(10:27:31 PM) dugi: arrest him pls
Calgon is offline   Reply With Quote
Old 11/04/2011, 09:10 AM   #4
Fro1sha
Big Clucker
 
Fro1sha's Avatar
 
Join Date: Nov 2009
Posts: 168
Reputation: 22
Default Re: Regular expression

Quote:
Originally Posted by Y_Less View Post
Ahh, I was wondering if anyone would ever do this - it has been something I've wanted for a while but never enough to actually get around to producing. Excellent work. One question, could you add pre-compilation for speed, example:

pawn Code:
new RegEx:rRPName = regex_build("([A-Z]{1,1})[a-z]{2,9}+_([A-Z]{1,1})[a-z]{2,9}");

regex_match_compile(name0, rRPName);
regex_match_compile(name1, rRPName);
regex_match_compile(name2, rRPName);

Also, that example doesn't actually check for valid emails:

http://haacked.com/archive/2007/08/2...s-until-i.aspx
Good suggestion =)

Quote:
Originally Posted by Calg00ne View Post
Thank you. SO MUCH!

I've been waiting for something like this forever, I've been having to create complex (well, I say complex, in comparison to regex, but functions generally containing a billion unnecessary checks in comparison to one regex statement).

Do you mind if I mirror the download?
Ok
__________________
[Plugin] MultiThread
[Plugin] GMT Timezone
[Plugin] Regular expression

Development any plugins, for the money.
Разработка любых плагинов за деньги.
Fro1sha is offline   Reply With Quote
Old 11/04/2011, 01:06 PM   #5
Fro1sha
Big Clucker
 
Fro1sha's Avatar
 
Join Date: Nov 2009
Posts: 168
Reputation: 22
Default Re: Regular expression

New version

0.2
- Added new natives
pawn Code:
native RegEx:regex_build(const expression[]);
native regex_delete(RegEx:expID);
native regex_isvalid(RegEx:expID);
native regex_delete_all();

native regex_match_exid(const string[], RegEx:expID);
native regex_search_exid(const string[], RegEx:expID);
native regex_replace_exid(const string[], RegEx:expID, const to[], dest[], size = sizeof dest);
__________________
[Plugin] MultiThread
[Plugin] GMT Timezone
[Plugin] Regular expression

Development any plugins, for the money.
Разработка любых плагинов за деньги.
Fro1sha is offline   Reply With Quote
Old 11/04/2011, 01:41 PM   #6
wheelman_WM
Huge Clucker
 
wheelman_WM's Avatar
 
Join Date: Jan 2011
Location: Sun
Posts: 403
Reputation: 0
Default Re: Regular expression

awesome xD
wheelman_WM is offline   Reply With Quote
Old 11/04/2011, 02:34 PM   #7
Romanius
Huge Clucker
 
Romanius's Avatar
 
Join Date: Jun 2009
Location: Bishkek, Kyrgyzstan
Posts: 422
Reputation: 24
Default Re: Regular expression

nice! хорошая работа! ждал давно!

P.S. See this http://gskinner.com/RegExr/
__________________
Romanius Studio

Ешь ананасы, рябчиков жуй, день твой последний приходит, буржуй!
Romanius is offline   Reply With Quote
Old 11/04/2011, 03:25 PM   #8
sooky
Big Clucker
 
Join Date: May 2010
Posts: 74
Reputation: 0
Default Re: Regular expression

Nice, thanks!
Mandatory relevant(ish) xkcd comic strip here: http://xkcd.com/208/
sooky is offline   Reply With Quote
Old 11/04/2011, 04:41 PM   #9
Calgon
Godfather
 
Join Date: Jan 2009
Posts: 6,210
Reputation: 835
Default Re: Regular expression

Heh, nice find.
__________________
If you don't know then Don't post here.

Quote:
(10:27:18 PM) dugi: hello is this the police?
(10:27:25 PM) dugi: Calgon is being mean
(10:27:31 PM) dugi: arrest him pls
Calgon is offline   Reply With Quote
Old 11/04/2011, 05:18 PM   #10
JaTochNietDan
High-roller
 
JaTochNietDan's Avatar
 
Join Date: Apr 2007
Location: Republic of Ireland
Posts: 4,302
Reputation: 357
Default Re: Regular expression

Ah, the beauty of regular expressions, it was only a matter of time before somebody decided to make a plugin for it for SA-MP. Thanks for the effort and submission.
__________________
Releases:
[Includes]: [jBan] | [jBanLite]
[Plugins]: [FileManager] | [Execute]
[Applications]: [Remote Administrator *NEW] | [Script King] | [RCON GUI]
[Tools]: [Random Spawn Array Generator]

Learn PAWN and more:
http://www.jatochnietdan.com


JaTochNietDan 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 08:53 PM
Regular San Andreas? Jakalak General 8 01/01/2009 08:04 PM


All times are GMT. The time now is 10:18 AM.


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