Jump to content

[Plugin] MTA Regex Module


sentike

Recommended Posts

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 by Guest
Link to comment
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

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 by Guest
Link to comment

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
  • 2 weeks later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...