WikiNatives:
boost
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);
#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);
}
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"));
}
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);
RegEx(.inc + .dll + .so)
RegEx Source
RegEx(.inc + .dll + .so)
RegEx Source
Mirror:
(depositfiles) RegEx(.inc+ .dll + .so)
(depositfiles) RegEx Source
Ahh, I was wondering if anyone would ever do this - it has been something I've wanted for a while but never enough to actually get around to producing. Excellent work. One question, could you add pre-compilation for speed, example:
pawn Code:
http://haacked.com/archive/2007/08/2...s-until-i.aspx |
Thank you. SO MUCH!
I've been waiting for something like this forever, I've been having to create complex (well, I say complex, in comparison to regex, but functions generally containing a billion unnecessary checks in comparison to one regex statement). Do you mind if I mirror the download? |
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);
stock IsValidRpNameEx(const string[])
{
static
RegEx:rRpName
;
if ( !rRpName )
{
rRpName = regex_build("[A-Z][a-z]+_[A-Z][a-z]{1,3}[A-Z]?[a-z]*");
}
return regex_match_exid(string, rRpName);
}
That can be vastly simplified, plus I doubt it will work on:
Code:
http://www.******.co.uk/ That is a valid web address. If you understand how web addresses are made you can improve the regex massively: Code:
([\w-]*://)?([\w-]+\.)+([\w-]+)(/[^\s]*)* Code:
optional-prefix://dot.spaced.domain/some/path.or?frankly&anything=else |
([\92w-]*://)?([\92w-]+\92.)+([\92w-]+)(/[^\92s]*)*
#define IsValidText(%1) regex_match(%1, "[a-zA-Z0-9]")
if(!IsValidText(string) return SendClientMessage(playerid, 0xFF0000FF, "Error: Only use letters from A till Z uppercase and undrcase! you can also use numbers 0 till 9");