sentike Posted January 14, 2013 Share Posted January 14, 2013 (edited) Hello, I want to provide opportunities for the long-awaited plug-MTA - Regular Expersion (regex). The plugin has three functions: -- Searching for a particular expression bool regex_search (string Source, string Pattern) -- Testing for the presence of arrays Expressions bool regex_match (string Source, string Pattern) -- Replace the expression an expression string regex_replace(string Source, string Pattern, string replacement) -- Information about the plugin bool regex_info () Plugin version: 1.2 Plugin authors: sentike https://dl.dropbox.com/u/69743126/%21sentike/mta/rtm_mta_regex.rar Change Log: V 1.2: 1. Function regex_replace V 1.1: 1. Increased reliability of the module; 2. Fixed a server crash at the wrong pattern 3. Added error output to the console v 0.5: 1. Function regex_search v 0.1A: 1. Function regex_match for example, we need to check the player's nickname, the format FirstName_LastName. So this is a regex that will do it for us. if(regex_match("Sentike","([A-Z]{1,1})[a-z]{2,9}_([A-Z]{1,1})[a-z]{2,9}") then --Bad login end if(regex_match("Sent_Style","([A-Z]{1,1})[a-z]{2,9}_([A-Z]{1,1})[a-z]{2,9}") then --Ok, next steps... end Or do we want to allow entry only numbers of a specified length We will use the pattern if(regex_match("777","[0-9]{3,3}") then -- (3 length). --Ok, next steps... end if(regex_match("777","[0-9]{,3}") then -- (0 to 3 length). --Ok, next steps... if(regex_match("777","[0-9]{3,}") then -- (3 length and more). --Ok, next steps... end --etc If you find bugs - inform me Edited January 15, 2013 by Guest Link to comment
csiguusz Posted January 14, 2013 Share Posted January 14, 2013 Isn't it possible to do this with the lua string library? Link to comment
sentike Posted January 14, 2013 Author Share Posted January 14, 2013 Lua does not support regex pattern, http://en.wikipedia.org/wiki/Regular_expression "([0-2]\\d|3[01])\\.(0\\d|1[012])\\.(\\d{4})" - Date Regex (dd.mm.yyyy) Link to comment
Scripting Moderators Sarrum Posted January 14, 2013 Scripting Moderators Share Posted January 14, 2013 Well done, very necessary thing. Link to comment
sentike Posted January 14, 2013 Author Share Posted January 14, 2013 Sarrum, Thank you. Was glad to help =) If you find bugs - inform me Link to comment
Arisu Posted January 14, 2013 Share Posted January 14, 2013 Are they perl-compatible? Support for captures? Link to comment
sentike Posted January 14, 2013 Author Share Posted January 14, 2013 Arisu, if it is fair, I do not know. I think that should work. Try it as usually the function call make LUA Link to comment
DutchCaffeine Posted January 14, 2013 Share Posted January 14, 2013 Just had a look in the source code, and I must say very well and clean scripted. Just the way I like seeing scripts. For the rest, thanks for sharing this module with us. Link to comment
CapY Posted January 14, 2013 Share Posted January 14, 2013 Hello, I want to provide opportunities for the long-awaited plug-MTA - Regular Expersion (regex).The plugin has three functions: *regex_search ([array], [expression]) - Searching for a particular expression *regex_match ([array], [expression]) - Testing for the presence of arrays Expressions *regex_info (); - Information about the plugin Plugin version: 0.1A Plugin authors: sentike https://dl.dropbox.com/u/69743126/%21sentike/mta/rtm_mta_regex.rar outputDebugString(tostring(regex_match("02.01.1990","([0-2]\\d|3[01])\\.(0\\d|1[012])\\.(\\d{4})"))) If you find bugs - inform me What is it for, what does it do, what can you do with it? Link to comment
sentike Posted January 14, 2013 Author Share Posted January 14, 2013 (edited) CapY, for example, we need to check the player's nickname, the format FirstName_LastName. So this is a regex that will do it for us. if(regex_match("Sentike","([A-Z]{1,1})[a-z]{2,9}_([A-Z]{1,1})[a-z]{2,9}") then --Bad login end if(regex_match("Sent_Style","([A-Z]{1,1})[a-z]{2,9}_([A-Z]{1,1})[a-z]{2,9}") then --Ok, next steps... end Or do we want to allow entry only numbers of a specified length We will use the pattern if(regex_match("777","[0-9]{3,3}") then -- (3 length). --Ok, next steps... end if(regex_match("777","[0-9]{,3}") then -- (0 to 3 length). --Ok, next steps... if(regex_match("777","[0-9]{3,}") then -- (3 length and more). --Ok, next steps... end --etc P.S. I used outputdebugstring, to verify that the module ! Edited January 15, 2013 by Guest Link to comment
Puma Posted January 14, 2013 Share Posted January 14, 2013 Not that I don't appreciate it, but could you give a proper definition of it's functionality, instead an examples ? Check strings for patterns? Link to comment
DutchCaffeine Posted January 15, 2013 Share Posted January 15, 2013 Regex is all about string patterns, it is a way better than lua's patterns. The thing is, it is very difficult to understand. Try google and search for "regex" or "regular expressions". Link to comment
sentike Posted January 15, 2013 Author Share Posted January 15, 2013 Change Log: V 1.1 1. Increased reliability of the module; 2. Fixed a server crash at the wrong pattern 3. Added error output to the console Link to comment
DutchCaffeine Posted January 16, 2013 Share Posted January 16, 2013 Little tool here to test your regular expressions, it is a very handy tool to use. It also has some community added expressions; http://gskinner.com/RegExr/ Link to comment
50p Posted January 16, 2013 Share Posted January 16, 2013 How about returning table of matches and their index of where in string it was found instead of bool? That would make more sense. Support group matching as well. What does regex_info() function do? It'd also make more sense if it returned a table like MTA's getVersion(). Link to comment
Kenix Posted January 29, 2013 Share Posted January 29, 2013 http://bugs.mtasa.com/view.php?id=7270 Link to comment
guix Posted February 5, 2013 Share Posted February 5, 2013 I never used regular expressions but it looks like Lua's patterns, only less useful, for example with string.match you can parse a line and store results into variables in a single function call (almost like sscanf). Not bad anyway, it's just not useful for me, might be for others Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now