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

Solved Regex MatchOffset - Does it work right ?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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:56.


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