View Single Post
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-16-2022 , 15:59   Regex MatchOffset - Does it work right ?
Reply With Quote #1

About this https://sm.alliedmods.net/new-api/re...ex/MatchOffset
- I'm not sure do I use it right.
Should this return offset of match in string ?
It now return offset of end of match in string.

Below example match STEAM_ id pattern.
output
Code:
sm plugins reload test
"<STEAM_0:1:23456> Baca bacardi jump over brown fox STEAM_7:8:9012345678 rolling down the hill, hit his head on rock"

numofmatch 2
> Baca bacardi jump over brown fox STEAM_7:8:9012345678 rolling down the hill, hit his head on rock
matchoffset 16

 rolling down the hill, hit his head on rock
matchoffset 71

[SM] Plugin test.smx reloaded successfully.


PHP Code:

#include <regex>

Regex rextest;

char loremipsum[] = {
    
"<STEAM_0:1:23456> Baca bacardi jump over brown fox \
    STEAM_7:8:9012345678 rolling down the hill, hit his head on rock"
}


public 
void OnPluginStart()
{
    
rextest = new Regex("(STEAM_\\d:\\d:\\d+)");

    
int numofmatch rextest.MatchAll(loremipsum);
    
int matchoffset;

    if(
numofmatch 0)
    {
        
PrintToServer("\"%s\"\n"loremipsum);

        
PrintToServer("numofmatch %i"numofmatch);

        for(
int a 1numofmatcha++)
        {
            for(
int b 0rextest.CaptureCount(a); b++)
            {
                
matchoffset rextest.MatchOffset(b);
                
PrintToServer("%s"loremipsum[matchoffset]);
                
PrintToServer("matchoffset %i\n"matchoffset);
            }
        }
    }


Last edited by Bacardi; 04-21-2022 at 12:11.
Bacardi is offline