[Plugin] Regular expression
#66

Quote:
Originally Posted by kadaradam
View Post
Hello,
I have a problem to checking valid names.My solution is:
Code:
^[a-z0-9@=_.()$]{3,24}$
But wont't work, the barkets ( [ ] ) are missing from the code, i don't know where should i put.
The
Code:
^[a-zA-Z0-9@=_\\[\\]\\.\\(\\)\\$]+$
is also won't work.
The first expression will not work because you haven't escaped special characters.
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/
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: 6 Guest(s)