[Plugin] Pawn.Regex - full support of regular expressions
#1

Pawn.Regex 1.1.3


Description:

Plugin that adds support for regular expressions in Pawn.

Why is it better than others plugins? Because it gives you an opportunity to get match groups.

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, &RegexMatch:mE_MATCH_FLAG:flags MATCH_DEFAULT);
native Regex_Search(const str[], Regex:r, &RegexMatch: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_GetGroup(RegexMatch:mindexdest[], &lengthsize sizeof dest);
native Match_Free(&RegexMatch: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:Regex_New("^\\/([\\w]+)\\s*(.+?)?\\s*$"),
        
RegexMatch:m,
        
cmd[16], params[256],
        
cmd_lengthparams_length;
    if (
Regex_Match(cmdtextrm))
    {
        
Match_GetGroup(m1cmdcmd_length);
        
Match_GetGroup(m2paramsparams_length);
        
Match_Free(m);
    }
    
printf("cmd '%s' (%d), params '%s' (%d)"cmdcmd_lengthparamsparams_length);
    
Regex_Delete(r);
    return 
1;
}
stock SplitAndPrint(str[])
{
    new 
Regex:Regex_New("[^\\s]+");
    if (
r)
    {
        new 
RegexMatch:m;
        new 
startpospos;
        while (
Regex_Search(strrmposstartpos))
        {
            new 
word[128], length;
            if (!
Match_GetGroup(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"
1.1.2:
- Changed naming conventions
- Added pawn.json
- Improved OnPlayerCommandText example
1.1.3:
- Fixed replacement null length
- Fixed multibyte strings
- Completely rewritten using samp-ptl

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

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


Messages In This Thread
Pawn.Regex - full support for regular expressions - by YourShadow - 14.06.2016, 07:11
Re: Pawn.Regex - full support of regular expressions - by Max_Andolini - 14.06.2016, 15:59
Re: Pawn.Regex - full support of regular expressions - by Roozevelt - 14.06.2016, 17:20
Re: Pawn.Regex - full support of regular expressions - by FuNkYTheGreat - 14.06.2016, 17:47
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 17.06.2016, 07:35
Re: Pawn.Regex - full support of regular expressions - by Gasman - 24.06.2016, 05:26
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 24.06.2016, 06:29
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 03.07.2016, 18:32
Re: Pawn.Regex - full support of regular expressions - by Luicy. - 03.07.2016, 19:22
Re: Pawn.Regex - full support of regular expressions - by Arturo226 - 03.07.2016, 20:01
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 09.07.2017, 15:45
Re: Pawn.Regex - full support of regular expressions - by Salik - 10.07.2017, 15:03
Re: Pawn.Regex - full support of regular expressions - by Barnwell - 18.07.2017, 00:22
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 24.03.2018, 13:19
Re: Pawn.Regex - full support of regular expressions - by sampkinq - 25.03.2018, 10:05
Re: Pawn.Regex - full support of regular expressions - by Kaperstone - 25.03.2018, 10:18
Re: Pawn.Regex - full support of regular expressions - by Kar - 29.03.2018, 05:40
Re: Pawn.Regex - full support of regular expressions - by Evocator - 29.03.2018, 08:01
Re: Pawn.Regex - full support of regular expressions - by Kaperstone - 30.03.2018, 14:08
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 14.04.2018, 07:39
Re: Pawn.Regex - full support of regular expressions - by [DK]Dark_Knight - 18.02.2019, 02:58
Re: Pawn.Regex - full support of regular expressions - by Calisthenics - 18.02.2019, 07:25
Re: Pawn.Regex - full support of regular expressions - by dirigent00 - 17.06.2019, 00:47
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 30.05.2020, 13:43
Re: Pawn.Regex - full support of regular expressions - by muningcat05 - 05.06.2020, 17:37
Re: Pawn.Regex - full support of regular expressions - by YourShadow - 05.06.2020, 19:07
Re: Pawn.Regex - full support of regular expressions - by muningcat05 - 05.06.2020, 19:41

Forum Jump:


Users browsing this thread: 1 Guest(s)