13.06.2013, 21:37
(
Last edited by Pooh7; 14/06/2013 at 12:20 AM.
)
Quote:
Hello,
I have a problem to checking valid names.My solution is: Code:
^[a-z0-9@=_.()$]{3,24}$ The Code:
^[a-zA-Z0-9@=_\\[\\]\\.\\(\\)\\$]+$ |
The second one should work and it actually does work. Here's an example of usage:
pawn Code:
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;
}
Output:
Code:
Matches Doesn't match Doesn't match
Here's a useful page where you can test your expressions. When using them in PAWN, you just have to double-escape characters, using 2 backslashes instead of 1: http://gskinner.com/RegExr/