[Plugin] Regular expression
#1

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:
Reply


Messages In This Thread
Regular expression 0.2 - by Fro1sha - 11.04.2011, 08:42
Re: Regular expression - by Calgon - 11.04.2011, 09:03
Re: Regular expression - by Fro1sha - 11.04.2011, 09:10
Re: Regular expression - by Fro1sha - 11.04.2011, 13:06
Re: Regular expression - by wheelman_WM - 11.04.2011, 13:41
Re: Regular expression - by Romanius - 11.04.2011, 14:34
Re: Regular expression - by sooky - 11.04.2011, 15:25
Re: Regular expression - by Calgon - 11.04.2011, 16:41
Re: Regular expression - by JaTochNietDan - 11.04.2011, 17:18
Re: Regular expression - by armyoftwo - 11.04.2011, 17:39
Re: Regular expression - by Abinesh™ - 16.04.2011, 11:40
Re: Regular expression - by Kwarde - 16.04.2011, 11:45
Re: Regular expression - by HP - 20.04.2011, 11:50
Re: Regular expression - by HP - 20.04.2011, 12:07
Re: Regular expression - by Romanius - 20.04.2011, 13:10
Re: Regular expression - by Romanius - 21.04.2011, 14:41
Re: Regular expression - by Zh3r0 - 04.05.2011, 19:02
Re: Regular expression - by Zh3r0 - 06.05.2011, 11:26
Re: Regular expression - by Laronic - 08.05.2011, 16:44
Re: Regular expression - by Unknown123 - 08.05.2011, 18:42
Re: Regular expression - by Blacklite - 08.05.2011, 21:16
Re: Regular expression - by Unknown123 - 09.05.2011, 12:39
Re: Regular expression - by Unknown123 - 09.05.2011, 12:55
Re: Regular expression - by Unknown123 - 09.05.2011, 13:15
Re: Regular expression - by Unknown123 - 09.05.2011, 13:29
Re: Regular expression - by Wyu - 09.05.2011, 13:44
Re: Regular expression - by Unknown123 - 09.05.2011, 13:47
Re: Regular expression - by Wyu - 09.05.2011, 13:51
Re: Regular expression - by Unknown123 - 09.05.2011, 13:54
Re: Regular expression - by HP - 13.05.2011, 06:58
Re: Regular expression - by songoku11 - 18.05.2011, 17:32
Re: Regular expression - by Blacklite - 19.05.2011, 03:33
Re: Regular expression - by Burridge - 26.05.2011, 10:36
Re: Regular expression - by Gamer_Z - 08.06.2011, 09:24
Re: Regular expression - by BASITJALIL - 08.06.2011, 09:28
Re: Regular expression - by Fro1sha - 08.06.2011, 12:46
Re: Regular expression - by Gamer_Z - 08.06.2011, 13:49
Re: Regular expression - by Fro1sha - 08.06.2011, 14:05
Re: Regular expression - by Gamer_Z - 08.06.2011, 14:30
Re: Regular expression - by BaubaS - 08.06.2011, 15:10
Re: Regular expression - by Fro1sha - 08.06.2011, 15:16
Re: Regular expression - by BaubaS - 08.06.2011, 15:27
Re: Regular expression - by Gamer_Z - 08.06.2011, 23:15
Re: Regular expression - by 1337connor - 09.06.2011, 04:07
Re: Regular expression - by BaubaS - 09.06.2011, 05:42
Re: Regular expression - by Gamer_Z - 09.06.2011, 06:56
Re: Regular expression - by Slice - 27.10.2011, 13:57
Re: Regular expression - by Kar - 27.10.2011, 14:03
Re: Regular expression - by Slice - 27.10.2011, 14:43
Re: Regular expression - by Kar - 27.10.2011, 15:21
Re: Regular expression - by Kar - 28.10.2011, 00:52
Re: Regular expression - by Lorenc_ - 17.01.2012, 05:52
Re: Regular expression - by jamesbond007 - 01.02.2012, 00:21
Re: Regular expression - by bryanwilgner - 01.03.2012, 19:36
Re: Regular expression - by s3rious - 01.03.2012, 19:39
Re: Regular expression - by bryanwilgner - 02.03.2012, 19:30
Re : Re: Regular expression - by Enchancer - 05.03.2012, 11:00
AW: Regular expression - by [N2L]DarkJoker - 05.03.2012, 12:59
Re: Regular expression - by Guitar - 05.03.2012, 19:28
Re: Regular expression - by Lorenc_ - 26.07.2012, 10:40
Re: Regular expression - by Slice - 26.07.2012, 10:45
Re: Regular expression - by Lorenc_ - 26.07.2012, 10:48
Re: Regular expression - by Slice - 26.07.2012, 10:56
Re: Regular expression - by DRIFT_HUNTER - 04.06.2013, 03:49
Re: Regular expression - by kadaradam - 13.06.2013, 19:34
Re: Regular expression - by Pooh7 - 13.06.2013, 21:37
Re: Regular expression - by 0x41726d79 - 18.10.2014, 18:31
Re: Regular expression - by Crayder - 22.10.2014, 20:11
Re: Regular expression - by Evocator - 06.08.2015, 20:13
Re: Regular expression - by Sasino97 - 04.06.2018, 10:27
Re: Regular expression - by [DK]Dark_Knight - 16.02.2019, 05:07
Re: Regular expression - by kristo - 16.02.2019, 13:18

Forum Jump:


Users browsing this thread: 3 Guest(s)