AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Regex. How to check if is match. (https://forums.alliedmods.net/showthread.php?t=88828)

unSeen 03-29-2009 13:52

[HELP] Regex. How to check if is match.
 
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.

fysiks 03-29-2009 14:39

Re: [HELP] Regex. How to check if is match.
 
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)
}


Arkshine 03-29-2009 19:21

Re: [HELP] Regex. How to check if is match.
 
As notes if you use the same pattern severals times, you should precompile the pattern using regex_compile.

unSeen 03-30-2009 05:47

Re: [HELP] Regex. How to check if is match.
 
isee thanks.


All times are GMT -4. The time now is 08:56.

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