[Plugin] Regular expression
#61

You can use 0-9, a-z, and A-Z as character groups instead of typing out the whole alphabet twice.
Reply
#62

Quote:
Originally Posted by Slice
View Post
You can use 0-9, a-z, and A-Z as character groups instead of typing out the whole alphabet twice.
I don't know how to really make regex expressions lol.
Reply
#63

Well, to test a player name you would see if this matches: "^[a-zA-Z0-9@=_\\[\\]\\.\\(\\)\\$]+$".
Reply
#64

Ah good....just making register system on server that will also register user on smf forum, and needed to validate email. Why the fuck nobody did not noticed that in pawn we need to use double slash?! For like 15 minutes i was surfing a net to find a solution (before i took a good look on examples here)

Here is a note for people that dont know that (like i didnt till now)
IN PAWN YOU CAN NOT USE SINGLE FRONT SLASH ( / ) IN CONSTANT STRING (It mean's continue string in new line) SO YOU USE DOUBLE FRONT SLASH // !

Here is a good email regex (tested many times)
CREDITS TO: Zrekam makerZ at http://regexlib.com
pawn Code:
regex_match(inputtext, "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$")
And thx for these amazing plugin, now we have an elegant,smart and fast way to match,search and replace text.
I just dont understand how people dont use it that much (as you can see nobody on forum is interested in these plugin) Only few people used it for some things (like zero for his admin system)
Reply
#65

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.
Reply
#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
#67

huh,

[0-9][^A-Za-z0-9]*[0-9][^A-Za-z0-9]*[0-9][^A-Za-z0-9]*[0-9]

this will work on PHP, but on your plugin not..
Reply
#68

https://github.com/iamcal/rfc822/blob/master/rfc822.php

Convert to pawn, for regex? :3
Reply
#69

Код:
[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
Reply
#70

This plugin is extremely useful. Thank you for creating it.
Worth to be bumped.
Reply
#71

Good Afternoon. I'm having a bit of trouble with the server crashing when i try to use a regex_replace

Код:
[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
This is the code
Код:
new str[32];
regex_replace("{FF00AA}Test", "{.*?}", "", str);
printf("REGEX %s", str);
Reply
#72

To everyone having issues, I suggest you to use a plugin that hasn't been without updates for almost a decade: https://sampforum.blast.hk/showthread.php?tid=609570
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)