View Single Post
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-19-2022 , 10:09   Re: Regex MatchOffset - Does it work right ?
Reply With Quote #2

Likes a bug.

However, your double-cycle is a bit strange.
Here is more clear test:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <regex>

Regex regex;

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()
{
    
char buf[128];
    
regex = new Regex("STEAM_\\d:\\d:\\d+");
    
    
int numMatches regex.MatchAll(loremipsum);
    if( 
numMatches )
    {
        
PrintToServer("Full string: \"%s\"\n"loremipsum);
        
PrintToServer("Num of matches: %i\n"numMatches);

        for(
int iMatch 0iMatch numMatchesiMatch ++)
        {
            
int offsetMatch regex.MatchOffset(iMatch);
            
regex.GetSubString(0bufsizeof(buf), iMatch);
            
            
PrintToServer("[substring:%i, offs:%i, len:%i]: %s"iMatchoffsetMatchstrlen(buf), buf);
        }
    }

Quote:
Full string: "<STEAM_0:1:23456> Baca bacardi jump over brown fox STEAM_7:8:9012345678 rolling down the hill, hit his head on rock"

Num of matches: 2

[substring:0, offs:16, len:15]: STEAM_0:1:23456
[substring:1, offs:71, len:20]: STEAM_7:8:9012345678
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 04-19-2022 at 10:16.
Dragokas is offline