SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/06/2016, 08:11 AM   #1
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Posts: 111
Reputation: 174
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 06:34 PM.
YourShadow is offline   Reply With Quote
Old 14/06/2016, 04:59 PM   #2
Max_Andolini
Huge Clucker
 
Max_Andolini's Avatar
 
Join Date: Oct 2013
Posts: 288
Reputation: 31
Default Re: Pawn.Regex - full support of regular expressions

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

Such wonderrful plugin , good job mate
__________________
• Left SA-MP.
• Roosevelt's stunt map pack : Click here
• SEF community
• Join now

Roozevelt is offline   Reply With Quote
Old 14/06/2016, 06:47 PM   #4
FuNkYTheGreat
Huge Clucker
 
FuNkYTheGreat's Avatar
 
Join Date: Jun 2016
Location: Pakistan.
Posts: 259
Reputation: 91
Default Re: Pawn.Regex - full support of regular expressions

Another Awesome Release by You,
YourShadow.
FuNkYTheGreat is offline   Reply With Quote
Old 17/06/2016, 08:35 AM   #5
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Posts: 111
Reputation: 174
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, 06:26 AM   #6
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, 07:29 AM   #7
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Posts: 111
Reputation: 174
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, 07:32 PM   #8
YourShadow
Big Clucker
 
YourShadow's Avatar
 
Join Date: Apr 2016
Posts: 111
Reputation: 174
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
Old 03/07/2016, 08:22 PM   #9
Luicy.
Banned
 
Join Date: Dec 2014
Location: Sweden, Skövde
Posts: 840
Reputation: 79
Default Re: Pawn.Regex - full support of regular expressions

Nice I guess, But what makes this so much better than strfind? All difference I can see are it's cleaner.
Luicy. is offline   Reply With Quote
Old 03/07/2016, 09:01 PM   #10
Arturo226
Little Clucker
 
Join Date: Oct 2009
Location: England
Posts: 17
Reputation: 0
Default Re: Pawn.Regex - full support of regular expressions

I've downloaded 1.1, however I get the following on server launch:
Code:
Plugin::AmxLoad: .inc-file version does not equal the plugin's version
Run time error 19: "File or function not found"
I am running this on a Windows server.
Arturo226 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 08:36 AM
[Tutorial] Converting to ALS 4 (Hook Method 7) Very Quickly With Regular Expressions [HLF]Southclaw Tutorials 1 29/07/2014 09:12 PM
Need help and full support monkuttan Server Support 33 16/11/2013 03:35 PM
expressions string to expressions? iJumbo Scripting Help 9 05/05/2013 01:56 AM
[REGEX] Acceptable nickname regular expression ikkentim Scripting Help 1 29/01/2013 09:13 PM


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


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