11.04.2011, 08:42
(
Last edited by Fro1sha; 15/04/2011 at 04:39 AM.
)
Description:
Examples:
Log:
WikiNatives:
boost
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);
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"));
}
- 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