Raised This Month: $51 Target: $400
 12% 

function regex_compile()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sutar
Senior Member
Join Date: Sep 2010
Old 08-22-2012 , 05:33   function regex_compile()
Reply With Quote #1

Hello everyone, please help make the function regex_compile()
It checks and blocks chat, if a match is found.

For example:
www.der.net - blocks.
www.der.com - blocks.
127.0. .... - blocks.
.13:27015 - blocks.

But the problem is that if you write:
13kb/sec. - blocks.
11 kb/sec. - blocks.

Can you help fix this problem?
And you can help, add the following words: icq, skype, Server.
When a match, too blocks the message...

Here is my script:

Code:
#include <amxmodx>
#include <amxmisc>
#include <regex>

new Regex:re, ret;
new err[32];

public plugin_init()
{
	register_plugin("Check Player Chat", "2.5", "Sutar")
	
	register_clcmd("say", "checkPlayerChat")
	register_clcmd("say_team", "checkPlayerChat")

	re = regex_compile("(?:\w+\.[a-z]{2,4}\b|(?:\s*\d+\s*\.){3}\b|([icq|skype|Server]))", ret, err, 31, "i");
}

public checkPlayerChat(id)
{
	new sayChat[128];
	read_args(sayChat, 127);
	
	if(strlen(sayChat) > 4)
	{
		if(regex_match_c(sayChat, re, ret))
		{
			client_cmd(id, "spk buttons/button10.wav")
			client_print(id, print_chat, "Stop advertising!")
			return PLUGIN_HANDLED
		}
	}
	return PLUGIN_CONTINUE
}

public plugin_end()
	regex_free(re);
Thank you very much

Last edited by Sutar; 08-22-2012 at 05:36.
Sutar is offline
Sutar
Senior Member
Join Date: Sep 2010
Old 09-25-2012 , 14:25   Re: function regex_compile()
Reply With Quote #2

UP!!!
so someone can help me?
Sutar is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-25-2012 , 15:11   Re: function regex_compile()
Reply With Quote #3

dont use regex for this.

Use loop to check string variable chars one by one, then you can take more control.
But i will not do that for you.
.Dare Devil. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-25-2012 , 20:02   Re: function regex_compile()
Reply With Quote #4

Quote:
Originally Posted by .Dare Devil. View Post
dont use regex for this.

Use loop to check string variable chars one by one, then you can take more control.
But i will not do that for you.
Clearly you don't know the power of Regex. If you are going to tell him to do it your way then you should do it also. This way you will see why you would never want to do it your way .
__________________
fysiks is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-25-2012 , 20:34   Re: function regex_compile()
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Clearly you don't know the power of Regex. If you are going to tell him to do it your way then you should do it also. This way you will see why you would never want to do it your way .
Im pretty sure in c, regex do the same.
Only different can be that regex can be little bit faster.
Not sure even that regex is faster, there are more checks than in my code will be.
Also i dont use regex, it was when i was young in scripting. ( Im still are but little bit older now )

But i noticed that sometimes can sorted data be a little bit wrong
like example word "regex compile" i get "regex xcompile". ( Its pawn problem,in c there are no such problems. )
But this will only happen when data is large and it called many times, i think linux will also fix that little problem for me.

Last edited by .Dare Devil.; 09-25-2012 at 20:58.
.Dare Devil. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-25-2012 , 20:46   Re: function regex_compile()
Reply With Quote #6

Quote:
Originally Posted by .Dare Devil. View Post
Im pretty sure in c, regex do the same.
Only different can be that regex can be little bit faster.
Not sure even that regex is faster, there are more checks than in my code will be.
Also i dont use regex, it was when i was young in scripting. ( Im still are but little bit older now )

But i noticed that sometimes can sorted data be a little bit wrong
like example word "regex combile" i get "regex xcombile". ( Its pawn problem,in c there are no such problems. )
But this will only happen when data is large and it called many times, i think linux will also fix that little problem for me.
After reading that post, I can only assume that your regex skills are only as good as you ability to spell compile correcly.
__________________
fysiks is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-25-2012 , 20:58   Re: function regex_compile()
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
After reading that post, I can only assume that your regex skills are only as good as you ability to spell compile correcly.
youre right, i dont know regex at all.
Also that spelling thing was doubletypo, i dont know why i writed that with b.

prove me that regex can be more powerful mine loop way : )

Last edited by .Dare Devil.; 09-25-2012 at 21:00.
.Dare Devil. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-25-2012 , 21:31   Re: function regex_compile()
Reply With Quote #8

Quote:
Originally Posted by .Dare Devil. View Post
prove me that regex can be more powerful mine loop way : )
I will not waste my time on you explaining what can be found all over the internet.
__________________
fysiks is offline
Sutar
Senior Member
Join Date: Sep 2010
Old 09-26-2012 , 02:17   Re: function regex_compile()
Reply With Quote #9

Quote:
Originally Posted by .Dare Devil. View Post
dont use regex for this.

Use loop to check string variable chars one by one, then you can take more control.
But i will not do that for you.
The cycle is a good thing, but with a regular expression, the code smaller and faster work cycles.
If no one can help with regex_compile(), maybe you can help write that the same cycle for these also checks?

And look here: http://www.amxmodx.org/funcwiki.php?go=module&id=17

Quote:
Provides Regular Expression functions. Regular Expressions let you describe ways in which to break down strings. They are extremely powerful. AMX Mod X uses the Perl Compatible RE library, you can read the specifics at their site. The PCRE AMX Mod X Module is maintained by BAILOPAN.
Quote:
Originally Posted by fysiks View Post
I will not waste my time on you explaining what can be found all over the internet.
I noticed that you are not small helping people. Thank you for this))
Help me in this case?))

Last edited by Sutar; 09-26-2012 at 02:28.
Sutar is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-26-2012 , 03:46   Re: function regex_compile()
Reply With Quote #10

Well, i've made a plugin with loops instead of RegEx because i want more control on string and also i need to do more checks ( RegEx can return many false detects when it comes to advertising patterns ). Of course RegEx it's powerful but it also have disadvantages like any other thing in scripting. Depending on what you want to check, you decide what to use and where. :-)

I think you should change your pattern. It doesn't match whole IP and website address. Take a look here
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 09-26-2012 at 03:56.
Alka is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode