Raised This Month: $ Target: $400
 0% 

[HELP] Regex. How to check if is match.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
unSeen
Member
Join Date: Sep 2008
Old 03-29-2009 , 13:52   [HELP] Regex. How to check if is match.
Reply With Quote #1

hey all.. I need little help with Regex.
I read about Regex in the documents of amxx.org and here when i search for question that people ask in this forum, but no one answered my question.

So anyways,
I wanna know how can i check if the pattern is match in the string.

for example let's say that my func is "isregex", I want to check for example:
if (isregex("I love girls", "l[oO0]ve") > 0) { server_print("yes it match") }

how do i do something like that?

thanks,
Elad.
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)
unSeen is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-29-2009 , 14:39   Re: [HELP] Regex. How to check if is match.
Reply With Quote #2

EDIT: I got the info from the amx documentation

This is one of my test regex codes:

Code:
new num, error[128]
new pattern[] = "[wW]\s*[tt]\s*[fF]"
new Regex:regexref = regex_match("my string to search",pattern,num,error,127)
if(regexref >= REGEX_OK)
{
    new tempstring[64]
    new i
    for(i=0; i<num; i++)
    {
        regex_substr(regexref, i, tempstring, 63)
        server_print("Found String%d: %s",i,tempstring)
    }
    server_print("regexref: %d", regexref)
    regex_free(regexref)
}
__________________

Last edited by fysiks; 03-29-2009 at 14:49.
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-29-2009 , 19:21   Re: [HELP] Regex. How to check if is match.
Reply With Quote #3

As notes if you use the same pattern severals times, you should precompile the pattern using regex_compile.
Arkshine is offline
unSeen
Member
Join Date: Sep 2008
Old 03-30-2009 , 05:47   Re: [HELP] Regex. How to check if is match.
Reply With Quote #4

isee thanks.
__________________
List of important things:
1. Respect you'r mother.
2. Respect you'r father.
3. Do not hit anyone.
4. Do not steal.
5. Do not flame.
7. You didn't see that there is no number 6.
8. You checked if number 7 is true.
9. You are laughing now.
10. You are double laughing because you understand the joke ;)
unSeen 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 08:56.


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