SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/06/2016, 07:11 AM   #1
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Location: Russia
Posts: 95
Reputation: 87
Exclamation Pawn.Regex - full support for regular expressions

Pawn.Regex 1.1.1


Description:
Pawn.Regex - a plugin that allows you to work with regular expressions.
Why is it better than others? Because it gives you an opportunity to get results of parsing, not just true/false if there is a match.

Natives:
PHP Code:
native regex:regex_new(const pattern[], E_REGEX_FLAG:flags REGEX_DEFAULTE_REGEX_GRAMMAR:grammar REGEX_ECMASCRIPT);
native regex_delete(&regex:r);

native regex_check(const str[], regex:rE_MATCH_FLAG:flags MATCH_DEFAULT);
native regex_match(const str[], regex:r, &match_results:mE_MATCH_FLAG:flags MATCH_DEFAULT);
native regex_search(const str[], regex:r, &match_results:m, &posstartpos 0E_MATCH_FLAG:flags MATCH_DEFAULT);
native regex_replace(const str[], regex:r, const fmt[], dest[], E_MATCH_FLAG:flags MATCH_DEFAULTsize sizeof dest);

native match_get_group(match_results:mindexdest[], &lengthsize sizeof dest);
native match_free(&match_results:m); 
Examples:
PHP Code:
#include <Pawn.Regex>

stock IsRpNickname(nickname[])
{
    new 
regex:regex_new("[A-Z][a-z]+_[A-Z][a-z]+");

    new 
check regex_check(nicknamer);

    
regex_delete(r);

    return 
check;
}

public 
OnPlayerCommandText(playeridcmdtext[])
{
    new
        
regex:r_with_param regex_new("\\/\\s*(\\w{1,15})\\s+(.+)"),
        
match_results:m,
        
cmd[16], params[256],
        
cmd_lengthparams_length;

    if (
regex_match(cmdtextr_with_paramm))
    {
        
match_get_group(m1cmdcmd_length);
        
match_get_group(m2paramsparams_length);

        
match_free(m);
    }
    else
    {
        new 
regex:regex_new("\\/\\s*(\\w{1,15})\\s*");

        if (
regex_match(cmdtextrm))
        {
            
match_get_group(m1cmdcmd_length);

            
match_free(m);
        }

        
regex_delete(r);
    }

    
printf("cmd '%s' (%d), params '%s' (%d)"cmdcmd_lengthparamsparams_length);

    
regex_delete(r_with_param);

    return 
1;
}

stock SplitAndPrint(str[])
{
    new 
regex:regex_new("[^\\s]+");

    if (
r)
    {
        new 
match_results:m;
        new 
startpospos;

        while (
regex_search(strrmposstartpos))
        {
            new 
word[128], length;

            if (!
match_get_group(m0wordlength))
            {
                break;
            }

            
printf("word: %s"word);

            
startpos += pos length;

            
match_free(m);
        }

        
regex_delete(r);
    }
}

stock ReplaceString(const str[], const regexp[], const fmt[], dest[], size sizeof dest)
{
    new 
regex:regex_new(regexp);

    if (
r)
    {
        
regex_replace(strrfmtdestMATCH_DEFAULTsize);

        
regex_delete(r);
    }
}

main()
{
    new 
str[128];

    
ReplaceString("Pawn.CMD""CMD""Regex"str);

    
printf("%s"str);

    
SplitAndPrint("4 8 15 16 23 42");

    
OnPlayerCommandText(-1"/ban 42");
    
OnPlayerCommandText(-1"/kill");

    
printf("%d %d",
                    
IsRpNickname("Your_Shadow"),
                    
IsRpNickname("urShadow"));

Changelog:
1.0:
- First release.
1.1:
- Fixed bugs.
- Changed native "match_get_group"
1.1.1:
- Fixed error "File or function is not found"

Download binaries:
https://github.com/urShadow/Pawn.Regex/releases

Source code:
https://github.com/urShadow/Pawn.Regex

Last edited by YourShadow; 09/07/2017 at 05:34 PM.
YourShadow is offline   Reply With Quote
Old 14/06/2016, 03:57 PM   #2
Ralfie
High-roller
 
Join Date: Nov 2013
Posts: 1,002
Reputation: 150
Default Re: Pawn.Regex - full support of regular expressions

Thank you, i will be testing this since all the old regex plugins have crash issues.
Ralfie is offline   Reply With Quote
Old 14/06/2016, 03:59 PM   #3
Max_Andolini
Huge Clucker
 
Max_Andolini's Avatar
 
Join Date: Oct 2013
Posts: 273
Reputation: 31
Default Re: Pawn.Regex - full support of regular expressions

You are Incredible
Max_Andolini is offline   Reply With Quote
Old 14/06/2016, 05:20 PM   #4
Roozevelt
Gangsta
 
Roozevelt's Avatar
 
Join Date: Jan 2016
Location: Tunsia
Posts: 505
Reputation: 103
Default Re: Pawn.Regex - full support of regular expressions

Such wonderrful plugin , good job mate
__________________
Party : Click here
Farm : Click here
Bmx Parkour Map : Click Here
Abondement airport "Stunt map" : Click here
Duel map : Click here
Derby map : Click here
Roozevelt is offline   Reply With Quote
Old 14/06/2016, 05:47 PM   #5
FuNkYTheGreat
Big Clucker
 
FuNkYTheGreat's Avatar
 
Join Date: Jun 2016
Location: Pakistan.
Posts: 147
Reputation: 51
Default Re: Pawn.Regex - full support of regular expressions

Another Awesome Release by You,
YourShadow.
FuNkYTheGreat is offline   Reply With Quote
Old 16/06/2016, 09:14 PM   #6
Ralfie
High-roller
 
Join Date: Nov 2013
Posts: 1,002
Reputation: 150
Default Re: Pawn.Regex - full support of regular expressions

Are we supposed to regex_search to detect occurrences in the middle of strings?
Can't we simply use regex_check?
http://pastebin.com/MVWFwAB2
Ralfie is offline   Reply With Quote
Old 17/06/2016, 07:35 AM   #7
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Location: Russia
Posts: 95
Reputation: 87
Default Re: Pawn.Regex - full support of regular expressions

Quote:
Originally Posted by Ralfie View Post
Are we supposed to regex_search to detect occurrences in the middle of strings?
Yes.
Quote:
Originally Posted by Ralfie View Post
Can't we simply use regex_check?
The entire target sequence must match the regular expression for this function to return true (i.e., without any additional characters before or after the match).
YourShadow is offline   Reply With Quote
Old 24/06/2016, 05:26 AM   #8
Gasman
Big Clucker
 
Gasman's Avatar
 
Join Date: May 2015
Location: VietNam
Posts: 69
Reputation: 71
Default Re: Pawn.Regex - full support of regular expressions

i can check Valid Email string with this?
Gasman is offline   Reply With Quote
Old 24/06/2016, 06:29 AM   #9
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Location: Russia
Posts: 95
Reputation: 87
Default Re: Pawn.Regex - full support of regular expressions

Quote:
Originally Posted by Gasman View Post
i can check Valid Email string with this?
Of course.
YourShadow is offline   Reply With Quote
Old 03/07/2016, 06:32 PM   #10
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Location: Russia
Posts: 95
Reputation: 87
Default Re: Pawn.Regex - full support of regular expressions

Pawn.Regex was updated to version 1.1.

- Fixed bugs.
- Changed native "match_get_group"
YourShadow 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
[Plugin] Regular Expressions Plugin v0.2 (RegEx) Koala818 Plugin Development 22 09/09/2016 07:36 AM
[Tutorial] Converting to ALS 4 (Hook Method 7) Very Quickly With Regular Expressions [HLF]Southclaw Tutorials 1 29/07/2014 08:12 PM
Need help and full support monkuttan Server Support 33 16/11/2013 02:35 PM
expressions string to expressions? iJumbo Scripting Help 9 05/05/2013 12:56 AM
[REGEX] Acceptable nickname regular expression ikkentim Scripting Help 1 29/01/2013 08:13 PM


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


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