26.07.2012, 10:45
You can use 0-9, a-z, and A-Z as character groups instead of typing out the whole alphabet twice.
regex_match(inputtext, "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$")
^[a-z0-9@=_.()$]{3,24}$
^[a-zA-Z0-9@=_\\[\\]\\.\\(\\)\\$]+$
Hello,
I have a problem to checking valid names.My solution is: Code:
^[a-z0-9@=_.()$]{3,24}$ The Code:
^[a-zA-Z0-9@=_\\[\\]\\.\\(\\)\\$]+$ |
new
RegEx:regex_name,
string[30]
;
public OnGameModeInit()
{
regex_name = regex_build("^[A-z0-9@=_\\[\\]\\.\\(\\)\\$]{3,24}$"); // Corrected a little bit; your is still valid though
// --------------------------------------------------
format(string, sizeof string, "[TAG]_Player@Name=$"); // A valid player name
if (regex_match_exid(string, regex_name))
print("Matches");
else
print("Doesn't match");
// --------------------------------------------------
format(string, sizeof string, "[TAG]_Player@Name=$!"); // An exclamation mark added at the end (invalid character)
if (regex_match_exid(string, regex_name))
print("Matches");
else
print("Doesn't match");
// --------------------------------------------------
format(string, sizeof string, "$_Player@Name=Player@Name"); // 25 characters long name (too long)
if (regex_match_exid(string, regex_name))
print("Matches");
else
print("Doesn't match");
return 1;
}
Matches Doesn't match Doesn't match
[21:13:08] [debug] Server crashed while executing Script.amx [21:13:08] [debug] AMX backtrace: [21:13:08] [debug] #0 native regex_exsearch () from libRegEx_static.so [21:13:08] [debug] #1 0002a9e8 in RegexBuild (text[]=@01580260 "done?") at D:\Script:66 [21:13:08] [debug] #2 001ad440 in ?? (... <2 arguments>) at D:\Script:42877 [21:13:08] [debug] #3 0000f5f8 in public OnPlayerText (playerid=0, text[]=@01580260 "done?") at D:\Script\YSI\y_hooks/impl.inc:885
[19:04:43] [debug] Server crashed while executing Debug.amx [19:04:43] [debug] AMX backtrace: [19:04:43] [debug] #0 native regex_replace () from regex.DLL [19:04:43] [debug] #1 00036dac in public OnRconCommand (cmd[]=@0007f93c "t") at C:\SAMP\filterscripts\Debug.pwn:52 [19:04:44] [debug] Native backtrace: [19:04:44] [debug] #0 7781d7cb in ?? () from C:\WINDOWS\SYSTEM32\ntdll.dll [19:04:44] [debug] #1 777ecd86 in ?? () from C:\WINDOWS\SYSTEM32\ntdll.dll [19:04:44] [debug] #2 7345df60 in ?? () from C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9415_none_508df7e2bcbccb90\MSVCR90.dll [19:04:44] [debug] #3 56c51f03 in ?? () from plugins\regex.DLL
new str[32]; regex_replace("{FF00AA}Test", "{.*?}", "", str); printf("REGEX %s", str);